Skip to content

Instantly share code, notes, and snippets.

@higuma
Created April 13, 2014 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save higuma/10581075 to your computer and use it in GitHub Desktop.
Save higuma/10581075 to your computer and use it in GitHub Desktop.
Rack解説 - Rackの構造とRack DSL ref: http://qiita.com/higuma/items/838f4f58bc4a0645950a
use Rack::ETag
use Rack::Deflater
use Rack::Static, urls: [''], root: 'public', index: 'index.html'
run lambda {|env|} # run proc {|env|} も可
GATEWAY_INTERFACE = CGI/1.1
HTTP_ACCEPT = text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
HTTP_ACCEPT_ENCODING = gzip,deflate,sdch
HTTP_ACCEPT_LANGUAGE = ja,en;q=0.8,en-US;q=0.6
HTTP_CONNECTION = keep-alive
HTTP_HOST = localhost:9292
HTTP_USER_AGENT = Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/33.0.1750.152 Chrome/33.0.1750.152 Safari/537.36
HTTP_VERSION = HTTP/1.1
PATH_INFO = /
QUERY_STRING =
REMOTE_ADDR = 127.0.0.1
REMOTE_HOST = localhost
REQUEST_METHOD = GET
REQUEST_PATH = /
...以下略...
Rack::Directory <-> Rack::Deflater <-> Rack::ETag <-> (Rack handler/server)
Rack::Static.new(app, options = {})
use Rack::Static, urls: [''], root: 'public', index: 'index.html'
use MIDDLEWARE1 [, ARG, ...]
use MIDDLEWARE2 [, ARG, ...]
...
run ENDPOINT.new [ARG, ...]
app = ENDPOINT.new([ARG, ...])
...
app = MIDDLEWARE2.new(app [, ARG, ...])
app = MIDDLEWARE1.new(app [, ARG, ...])
Rack::Handler::[SERVER_NAME].run(app, ...)
...
PATH_INFO = /foo/bar
QUERY_STRING = abc=xyz
...
REQUEST_PATH = /foo/bar
REQUEST_URI = http://localhost:9292/foo/bar?abc=xyz
...
run ShowEnv.new
endpoint <-> middleware[s] ... <-> (Rack handler) <-> (server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment