Skip to content

Instantly share code, notes, and snippets.

@keisatou
Created November 20, 2013 17:39
Show Gist options
  • Save keisatou/7567550 to your computer and use it in GitHub Desktop.
Save keisatou/7567550 to your computer and use it in GitHub Desktop.
http://bayashi.net/static/slide/20131120/index.html のコピペです。一覧できるようにメモ。
# see the following site for details: http://bayashi.net/static/slide/20131120/index.html
# 1
$ plackup -e 'sub {
[ 200, [], ["OK"] ]
}'
$ curl http://localhost:5000/
OK
# 2
$ plackup -e 'sub {
[ 200,
["Content-Type" => "text/html"],
["<html><head><head><body>HTML</body></html>"]
]
}'
$ curl http://localhost:5000/
<html><head><head><body>HTML</body></html>
# 3
$ plackup -e 'sub {
[ 200,
["Content-Type" => "application/json"],
[ qq|{"friend": 0}| ]
]
}'
$ curl http://localhost:5000/
{friend: 0}
# 4
$ plackup -MDDP -e 'sub {
[ 200, [], [p(@_)] ]
}'
$ curl http://localhost:5000/
[
[0] {
HTTP_ACCEPT "*/*",
HTTP_HOST "localhost:5000",
HTTP_USER_AGENT "curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5",
PATH_INFO "/",
psgi.errors *main::STDERR (read/write, layers: unix perlio),
...
# 5
$ plackup -s Starlet -e 'sub {
[ 200, [], [$$] ]
}'
$ curl http://localhost:5000/
29045
$ curl http://localhost:5000/
29046
$ curl -I http://localhost:5000/
HTTP/1.0 200 OK
Date: Wed, 20 Nov 2013 08:56:48 GMT
Server: Plack::Handler::Starlet
# Plack::Middleware::* memo
DebugRequestParams
REPL
InteractiveDebugger
# Plack::App::* とかにも便利なモジュールあるらしい
## User-agentから色々判定
$ plackup -MDDP -e '
enable "Woothee";
sub {
[ 200, [], [p(@_)] ]
}
'
$ curl http://localhost:5000/
psgix.woothee {
category "UNKNOWN",
name "UNKNOWN",
os "UNKNOWN",
vendor "UNKNOWN",
version "UNKNOWN"
},
$ curl http://localhost:5000/ -A 'Googlebot'
psgix.woothee {
category "crawler",
name "misc crawler",
os "UNKNOWN",
vendor "UNKNOWN",
version "UNKNOWN"
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment