HORIZON HASKELLDocslts/ghc-9.14.x6d5fdfd2026-10-12Search packagesCtrl K
Theme: |

GHC 9.14.1 · lts/ghc-9.14.x · 6d5fdfd · 2026-10-12

Modulewarp-3.4.16Haskell2010

Network.Wai.Handler.Warp.Internal

IMPORTANT NOTICE

This module exports internals mainly to provide the warp-tls package with tools to implement what it needs to. This module/API should NOT be expected to remain stable at all, even between minor releases.

If you see a use case for these functions or types for other purposes, please create an issue in the repository so that we might add it to the main Network.Wai.Handler.Warp API.

Contents
  1. Settings
  2. Connection counter
  3. Server state
  4. Low level run functions
  5. Connection
  6. Receive
  7. Buffer
  8. Sendfile
  9. Version
  10. Data types
  11. Time out manager
  12. File descriptor cache
  13. File information cache
  14. Date
  15. Request and response
  16. Platform dependent helper functions
  17. Misc
Synopsis
  • Packagewarp-3.4.16
  • Exports73
  • LanguageHaskell2010
  • LicenceMIT
  • SourceInternal.hs

Settings

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

Connection counter

Server state

Low level run functions

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.

Connection

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

Buffer

datadata WriteBuffer

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

Constructors

Sendfile

Version

Data types

The internals of IndexedHeader have changed since 3.4.15, so we keep exporting it as a type synonym, but it is now a record instead of an array. As such there's no more requestMaxIndex, but we provide a blank defaultIndexRequestHeader.

Time out manager

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.

valuekillManager :: Manager -> IO ()

Deprecated. This function does nothing since version 0.3.0

Obsoleted since version 0.3.0 Is now equivalent to pure ().

valuestopManager :: Manager -> IO ()

Deprecated. This function does nothing since version 0.3.0

Obsoleted since version 0.3.0 Is now equivalent to pure ().

File descriptor cache

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

File information cache

Date

Request and response

datadata Source

Type for input streaming.

Caveat: a Source is meant to be used in one thread only.

valuerecvRequest
  1. :: FirstRequest
  2. -> Settings
  3. -> Connection
  4. -> InternalInfo
  5. -> Handle
  6. -> SockAddr

    Peer's address.

  7. -> Source

    Where HTTP request comes from.

  8. -> Transport
  9. -> IO (Request, Maybe (IORef Int), IndexedRequestHeader, IO ByteString)

    Request passed to Application, how many bytes remain to be consumed, if known IndexedHeader of HTTP request for internal use, Body producing action used for flushing the request body

Receiving a HTTP request from Connection and parsing its header to create Request.

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

    HTTP request.

  6. -> IndexedRequestHeader

    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

Misc