Snap.Internal.Http.Server.Types

snap-server-1.1.2.1: A web server for the Snap Framework

Safe Haskell | None
Language | Haskell2010

Snap.Internal.Http.Server.Types

Contents

- Handlers
- Socket types

Description

Types internal to the implementation of the Snap HTTP server.

Synopsis

- data ServerConfig hookState = ServerConfig {
  - _logAccess :: !(Request -> Response -> Word64 -> IO ())
  - _logError :: !(Builder -> IO ())
  - _onNewRequest :: !(NewRequestHook hookState)
  - _onParse :: !(ParseHook hookState)
  - _onUserHandlerFinished :: !(UserHandlerFinishedHook hookState)
  - _onDataFinished :: !(DataFinishedHook hookState)
  - _onException :: !(ExceptionHook hookState)
  - _onEscape :: !(EscapeSnapHook hookState)
  - _localHostname :: !ByteString
  - _defaultTimeout :: !Int
  - _isSecure :: !Bool
  - _numAcceptLoops :: !Int
  }
- data PerSessionData = PerSessionData {
  - _forceConnectionClose :: !(IORef Bool)
  - _twiddleTimeout :: !((Int -> Int) -> IO ())
  - _isNewConnection :: !(IORef Bool)
  - _sendfileHandler :: !SendFileHandler
  - _localAddress :: !ByteString
  - _localPort :: !Int
  - _remoteAddress :: !ByteString
  - _remotePort :: !Int
  - _readEnd :: !(InputStream ByteString)
  - _writeEnd :: !(OutputStream ByteString)
  }
- type DataFinishedHook hookState = IORef hookState -> Request -> Response -> IO ()
- type EscapeSnapHook hookState = IORef hookState -> IO ()
- type ExceptionHook hookState = IORef hookState -> SomeException -> IO ()
- type ParseHook hookState = IORef hookState -> Request -> IO ()
- type NewRequestHook hookState = PerSessionData -> IO hookState
- type UserHandlerFinishedHook hookState = IORef hookState -> Request -> Response -> IO ()
- type SendFileHandler = Buffer -> Builder -> FilePath -> Word64 -> Word64 -> IO ()
- type ServerHandler hookState = ServerConfig hookState -> PerSessionData -> Request -> IO (Request, Response)
- newtype AcceptFunc = AcceptFunc {
  - runAcceptFunc :: (forall a. IO a -> IO a) -> IO (SendFileHandler, ByteString, Int, ByteString, Int, InputStream ByteString, OutputStream ByteString, IO ())
  }
- data SocketConfig
  - = StartListening ByteString Int
  - | PreBound Socket

# Documentation

data ServerConfig hookState #

Data and services that all HTTP response handlers share.

Constructors

ServerConfig |
Fields _logAccess :: !(Request -> Response -> Word64 -> IO ()) _logError :: !(Builder -> IO ()) _onNewRequest :: !(NewRequestHook hookState) _onParse :: !(ParseHook hookState) _onUserHandlerFinished :: !(UserHandlerFinishedHook hookState) _onDataFinished :: !(DataFinishedHook hookState) _onException :: !(ExceptionHook hookState) _onEscape :: !(EscapeSnapHook hookState) _localHostname :: !ByteString will be overridden by a `Host` header if it appears. _defaultTimeout :: !Int _isSecure :: !Bool _numAcceptLoops :: !Int Number of accept loops to spawn.

data PerSessionData #

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

Constructors

PerSessionData |
Fields _forceConnectionClose :: !(IORef Bool) If the bool stored in this IORef becomes true, the server will close the connection after the current request is processed. _twiddleTimeout :: !((Int -> Int) -> IO ()) An IO action to modify the current request timeout. _isNewConnection :: !(IORef Bool) The value stored in this IORef is True if this request is the first on a new connection, and False if it is a subsequent keep-alive request. _sendfileHandler :: !SendFileHandler The function called when we want to use `sendfile().` _localAddress :: !ByteString The server's idea of its local address. _localPort :: !Int The listening port number. _remoteAddress :: !ByteString The address of the remote user. _remotePort :: !Int The remote user's port. _readEnd :: !(InputStream ByteString) The read end of the socket connection. _writeEnd :: !(OutputStream ByteString) The write end of the socket connection.

type DataFinishedHook hookState = IORef hookState -> Request -> Response -> IO () #

The `DataFinishedHook` is called once the server has finished sending the HTTP response to the client.

type EscapeSnapHook hookState = IORef hookState -> IO () #

The `EscapeSnapHook` is called if the user handler escapes the HTTP session, e.g. for websockets.

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

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

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

type UserHandlerFinishedHook hookState = IORef hookState -> Request -> Response -> IO () #

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

type SendFileHandler #

Arguments

= Buffer | builder buffer
-> Builder | status line and headers
-> FilePath | file to send
-> Word64 | start offset
-> Word64 | number of bytes
-> IO () |

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 #

Arguments

= ServerConfig hookState | global server config
-> PerSessionData | per-connection data
-> Request | HTTP request object
-> IO (Request, Response) |

This function, provided to the web server internals from the outside, is responsible for producing a `Response` once the server has parsed the `Request`.

newtype AcceptFunc #

Constructors

AcceptFunc |
Fields runAcceptFunc :: (forall a. IO a -> IO a) -> IO (SendFileHandler, ByteString, Int, ByteString, Int, InputStream ByteString, OutputStream ByteString, IO ())

# Socket types

data SocketConfig #

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.

Constructors

StartListening ByteString Int |
PreBound Socket |