Clack

Revenge of Lisp in Web

Chapter 4: The Environment

English | 日本語

Let's have a good look at env. When you access a server on localhost, ex. http://localhost:4242/sns/member?id=3, the env is something like this:

(:request-method :GET
 :script-name ""
 :path-info "/sns/member"
 :query-string "id=3"
 :server-name "localhost"
 :server-port 4242
 :request-uri "/sns/member?id=3"
 :server-protocol :HTTP/1.1
 :http-user-agent "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-US) ..."
 :remote-addr "127.0.0.1"
 :remote-port 26077
 :http-referer nil
 :http-host "localhost:4242"
 :http-cookies nil)

Below is the details of the keys and values of env. You don't need to memorize all of them, except that you are creating a Clack handler or an adapter between Clack and a web server.


:request-method (Required, Keyword)
The HTTP request method: :GET , :HEAD , :OPTIONS , :PUT , :POST , or :DELETE .
:script-name (Required, String)
The initial portion of the request URI path that corresponds to the Clack application. The value of this key may be an empty string when the client is accessing the application represented by the server's root URI. Otherwise, it is a non-empty string starting with a forward slash ( / ).
:path-info (Required, String)
The remainder of the request URI path. The value of this key may be an empty string when you access the application represented by the server's root URI with no trailing slash.
:query-string (Optional, String)
The portion of the request URI that follows the ? , if any. This key may have no value at all while the key itself always exists.
:server-name (Required, String)
The resolved server name or the server IP address.
:server-port (Required, Integer)
The port on which the request is being handled.
:server-protocol (Required, Keyword)
The version of the protocol the client used to send the request: typically :HTTP/1.0 or :HTTP/1.1 .
:request-uri (Required, String)
The request URI. Always starts with "/".
:raw-body (Optional, Stream)
:http-user-agent (Optional, String)
:http-referer (Optional, String)
:remote-addr (Required, String)
:remote-port (Required, Integer)
:http-server (Required, Keyword)
The name of the Clack handler, such as :hunchentoot and :apache.