HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulesnap-server-1.1.2.1Haskell2010

Snap.Http.Server.Types

Types used by the Snap HTTP Server.

  • 12 types
  • 31 values
datadata ServerConfig hookState
#

Data and services that all HTTP response handlers share.

datadata PerSessionData
#

All of the things a session needs to service a single HTTP request.

ServerConfig

1 declaration

getters/setters

PerSessionData

0 declarations

getters

HTTP lifecycle

0 declarations

Request / Response lifecycle for "normal" requests (i.e. without errors):

  1. accept a new connection, set it up (e.g. with SSL)

  2. create a PerSessionData object

  3. Enter the SessionHandler, which:

  4. calls the NewRequestHook, making a new hookState object.

  5. parses the HTTP request. If the session is over, we stop here.

  6. calls the ParseHook

  7. enters the ServerHandler, which is provided by another part of the framework

  8. the server handler passes control to the user handler

  9. a Response is produced, and the UserHandlerFinishedHook is called.

  10. the Response is written to the client

  11. the DataFinishedHook is called.

  12. we go to #3.

Hooks

6 declarations

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).

typetype ExceptionHook hookState = IORef hookState -> SomeException -> IO ()
#

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.

typetype ParseHook hookState = IORef hookState -> Request -> IO ()
#

The ParseHook is called after the HTTP Request has been parsed by the server, but before the user handler starts running.

typetype NewRequestHook hookState = PerSessionData -> IO hookState
#

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.

Handlers

3 declarations

Socket types

1 declaration