Data and services that all HTTP response handlers share.
Modulesnap-server-1.1.2.1Haskell2010
Snap.Http.Server.Types
Types used by the Snap HTTP Server.
Contents
Synopsis
- data ServerConfig
- data PerSessionData
- value emptyServerConfig
- value getDefaultTimeout
- value getIsSecure
- value getLocalHostname
- value getLogAccess
- value getLogError
- value getNumAcceptLoops
- value getOnDataFinished
- value getOnEscape
- value getOnException
- value getOnNewRequest
- value getOnParse
- value getOnUserHandlerFinished
- value setDefaultTimeout
- value setIsSecure
- value setLocalHostname
- value setLogAccess
- value setLogError
- value setNumAcceptLoops
- value setOnDataFinished
- value setOnEscape
- value setOnException
- value setOnNewRequest
- value setOnParse
- value setOnUserHandlerFinished
- value getTwiddleTimeout
- value isNewConnection
- value getLocalAddress
- value getLocalPort
- value getRemoteAddress
- value getRemotePort
- type DataFinishedHook
- type EscapeSnapHook
- type ExceptionHook
- type ParseHook
- type NewRequestHook
- type UserHandlerFinishedHook
- type SendFileHandler
- type ServerHandler
- newtype AcceptFunc
- data SocketConfig
- Packagesnap-server-1.1.2.1
- Exports43
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceTypes.hs
All of the things a session needs to service a single HTTP request.
ServerConfig
getters/setters
PerSessionData
getters
HTTP lifecycle
Request / Response lifecycle for "normal" requests (i.e. without errors):
accept a new connection, set it up (e.g. with SSL)
create a PerSessionData object
Enter the
SessionHandler, which:calls the NewRequestHook, making a new hookState object.
parses the HTTP request. If the session is over, we stop here.
calls the ParseHook
enters the ServerHandler, which is provided by another part of the framework
the server handler passes control to the user handler
a Response is produced, and the UserHandlerFinishedHook is called.
the Response is written to the client
the DataFinishedHook is called.
we go to #3.
Hooks
At various critical points in the HTTP lifecycle, the Snap server will call user-defined "hooks" that can be used for instrumentation or tracing of the process of building the HTTP response. The first hook called, the NewRequestHook, will generate a "hookState" object (having some user-defined abstract type), and this object will be passed to the rest of the hooks as the server handles the process of responding to the HTTP request.
For example, you could pass a set of hooks to the Snap server that measured
timings for each URI handled by the server to produce online statistics and
metrics using something like statsd (https://github.com/etsy/statsd).
The DataFinishedHook is called once the server has finished sending the HTTP response to the client.
The EscapeSnapHook is called if the user handler escapes the HTTP session, e.g. for websockets.
The ExceptionHook is called if an exception reaches the toplevel of the server, i.e. if an exception leaks out of the user handler or if an exception is raised during the sending of the HTTP response data.
The ParseHook is called after the HTTP Request has been parsed by the server, but before the user handler starts running.
The NewRequestHook is called once processing for an HTTP request begins, i.e. after the connection has been accepted and we know that there's data available to read from the socket. The IORef passed to the hook initially contains a bottom value that will throw an exception if evaluated.
The UserHandlerFinishedHook is called once the user handler has finished running, but before the data for the HTTP response starts being sent to the client.
Handlers
A SendFileHandler is called if the user handler requests that a file be
sent using sendfile() on systems that support it (Linux, Mac OSX, and
FreeBSD).
type ServerHandler hookState = ServerConfig hookState -> PerSessionData -> Request -> IO (Request, Response)Socket types
Either the server should start listening on the given interface / port
combination, or the server should start up with a Socket that has already
had bind() and listen() called on it.