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

  • Packagewarp-3.4.9
  • Exports65
  • LanguageHaskell2010
  • LicenceMIT
  • SourceSettings.hs

Settings

2 declarations
datadata Settings
#

Various Warp server settings. This is purposely kept as an abstract data type so that new settings can be added without breaking backwards compatibility. In order to create a Settings value, use defaultSettings and the various 'set' functions to modify individual fields. For example:

setTimeout 20 defaultSettings

Constructors

Low level run functions

4 declarations

The connection setup action would be expensive. A good example is initialization of TLS. So, this converts the connection setup action to the connection maker which will be executed after forking a new worker thread. Then this calls runSettingsConnectionMaker with the connection maker. This allows the expensive computations to be performed in a separate worker thread instead of the main server loop.

Since 1.3.5

Connection

2 declarations
datadata Connection
#

Data type to manipulate IO actions for connections. This is used to abstract IO actions for plain HTTP and HTTP over TLS.

Constructors

Receive

typetype Recv = IO ByteString
#

Type for the receiving function with a buffer pool.

Buffer

datadata WriteBuffer
#

A write buffer of a specified size containing bytes and a way to free the buffer.

Constructors

valuecopy :: Buffer -> ByteString -> IO Buffer
#

Copying the bytestring to the buffer. This function returns the point where the next copy should start.

Sendfile

valuereadSendFile :: Buffer -> BufSize -> (ByteString -> IO ()) -> SendFile
#

Function to send a file based on pread()/send() for Unix. This makes use of the file descriptor cache. For Windows, this is emulated by Handle.

Since: 3.1.0

Version

1 declaration

Data types

4 declarations
valuerequestMaxIndex :: Int
#

The size for IndexedHeader for HTTP Request. From 0 to this corresponds to:

  • "Content-Length"

  • "Transfer-Encoding"

  • "Expect"

  • "Connection"

  • "Range"

  • "Host"

  • "If-Modified-Since"

  • "If-Unmodified-Since"

  • "If-Range"

  • "Referer"

  • "User-Agent"

  • "If-Match"

  • "If-None-Match"

Time out manager

18 declarations

In order to provide slowloris protection, Warp provides timeout handlers. We follow these rules:

  • A timeout is created when a connection is opened.

  • When all request headers are read, the timeout is tickled.

  • Every time at least the slowloris size settings number of bytes of the request body are read, the timeout is tickled.

  • The timeout is paused while executing user code. This will apply to both the application itself, and a ResponseSource response. The timeout is resumed as soon as we return from user code.

  • Every time data is successfully sent to the client, the timeout is tickled.

valueinitialize :: Int -> IO Manager
#

Creating timeout manager which works every N micro seconds where N is the first argument.

datadata Handle
#

A handle used by a timeout manager.

File descriptor cache

6 declarations
valuewithFdCache :: Int -> ((FilePath -> IO (Maybe Fd, Refresh)) -> IO a) -> IO a
#

Creating MutableFdCache and executing the action in the second argument. The first argument is a cache duration in microseconds.

newtypenewtype Fd
#
Instances15Bounded, Enum, Eq, Integral, Num, Ord, …
  • Bounded FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Enum FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Eq FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Integral FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Num FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ord FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Read FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Real FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Show FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Ix FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Bits FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • FiniteBits FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Storable FdDefined in ghc-internal-9.1003.0 · GHC.Internal.System.Posix.Types
  • Prim FdDefined in primitive-0.9.1.0 · Data.Primitive.Types
  • ControlMessage [Fd]Defined in network-3.2.8.0 · Network.Socket.Posix.Cmsg
typetype Refresh = IO ()
#

An action to activate a Fd cache entry.

File information cache

3 declarations
valuewithFileInfoCache :: Int -> ((FilePath -> IO FileInfo) -> IO a) -> IO a
#

Creating a file information cache and executing the action in the second argument. The first argument is a cache duration in microseconds.

Date

2 declarations

Request and response

4 declarations
datadata Source
#

Type for input streaming.

valuesendResponse
  1. :: Settings
  2. -> Connection
  3. -> InternalInfo
  4. -> Handle
  5. -> Request

    HTTP request.

  6. -> IndexedHeader

    Indexed header of HTTP request.

  7. -> IO ByteString

    source from client, for raw response

  8. -> Response

    HTTP response including status code and response header.

  9. -> IO Bool

    Returing True if the connection is persistent.

#

Sending a HTTP response to Connection according to Response.

Applications/middlewares MUST provide a proper ResponseHeaders. so that inconsistency does not happen. No header is deleted by this function.

Especially, Applications/middlewares MUST provide a proper Content-Type. They MUST NOT provide Content-Length, Content-Range, and Transfer-Encoding because they are inserted, when necessary, regardless they already exist. This function does not insert Content-Encoding. It's middleware's responsibility.

The Date and Server header is added if not exist in HTTP response header.

There are three basic APIs to create Response:

responseBuilder :: Status -> ResponseHeaders -> Builder -> Response

HTTP response body is created from

Builder

. Transfer-Encoding: chunked is used in HTTP/1.1.

responseStream :: Status -> ResponseHeaders -> StreamingBody -> Response

HTTP response body is created from

Builder

. Transfer-Encoding: chunked is used in HTTP/1.1.

responseRaw :: (IO ByteString -> (ByteString -> IO ()) -> IO ()) -> Response -> Response

No header is added and no Transfer-Encoding: is applied.

responseFile :: Status -> ResponseHeaders -> FilePath -> Maybe FilePart -> Response

HTTP response body is sent (by sendfile(), if possible) for GET method. HTTP response body is not sent by HEAD method. Content-Length and Content-Range are automatically added into the HTTP response header if necessary. If Content-Length and Content-Range exist in the HTTP response header, they would cause inconsistency. "Accept-Ranges: bytes" is also inserted.

Applications are categorized into simple and sophisticated. Sophisticated applications should specify Just to Maybe FilePart. They should treat the conditional request by themselves. A proper Status (200 or 206) must be provided.

Simple applications should specify Nothing to Maybe FilePart. The size of the specified file is obtained by disk access or from the file info cache. If-Modified-Since, If-Unmodified-Since, If-Range and Range are processed. Since a proper status is chosen, Status is ignored. Last-Modified is inserted.

Platform dependent helper functions

2 declarations

Misc

4 declarations