warp-3.4.7: A fast, light-weight web server for WAI applications.

Safe Haskell | None
Language | Haskell2010

Network.Wai.Handler.Warp.Internal

Contents

- Settings
- Low level run functions
- Connection
  - Receive
  - Buffer
  - Sendfile
- Version
- Data types
- Time out manager
- File descriptor cache
- File information cache
- Date
- Request and response
- Platform dependent helper functions
- Misc

Synopsis

- data Settings = Settings {
  - settingsPort :: Port
  - settingsHost :: HostPreference
  - settingsOnException :: Maybe Request -> SomeException -> IO ()
  - settingsOnExceptionResponse :: SomeException -> Response
  - settingsOnOpen :: SockAddr -> IO Bool
  - settingsOnClose :: SockAddr -> IO ()
  - settingsTimeout :: Int
  - settingsManager :: Maybe Manager
  - settingsFdCacheDuration :: Int
  - settingsFileInfoCacheDuration :: Int
  - settingsBeforeMainLoop :: IO ()
  - settingsFork :: ((forall a. IO a -> IO a) -> IO ()) -> IO ()
  - settingsAccept :: Socket -> IO (Socket, SockAddr)
  - settingsNoParsePath :: Bool
  - settingsInstallShutdownHandler :: IO () -> IO ()
  - settingsServerName :: ByteString
  - settingsMaximumBodyFlush :: Maybe Int
  - settingsProxyProtocol :: ProxyProtocol
  - settingsSlowlorisSize :: Int
  - settingsHTTP2Enabled :: Bool
  - settingsLogger :: Request -> Status -> Maybe Integer -> IO ()
  - settingsServerPushLogger :: Request -> ByteString -> Integer -> IO ()
  - settingsGracefulShutdownTimeout :: Maybe Int
  - settingsGracefulCloseTimeout1 :: Int
  - settingsGracefulCloseTimeout2 :: Int
  - settingsMaxTotalHeaderLength :: Int
  - settingsAltSvc :: Maybe ByteString
  - settingsMaxBuilderResponseBufferSize :: Int
  }
- data ProxyProtocol
  - = ProxyProtocolNone
  - | ProxyProtocolRequired
  - | ProxyProtocolOptional
- runSettingsConnection :: Settings -> IO (Connection, SockAddr) -> Application -> IO ()
- runSettingsConnectionMaker :: Settings -> IO (IO Connection, SockAddr) -> Application -> IO ()
- runSettingsConnectionMakerSecure :: Settings -> IO (IO (Connection, Transport), SockAddr) -> Application -> IO ()
- data Transport
  - = TCP
  - | TLS {
    - tlsMajorVersion :: Int
    - tlsMinorVersion :: Int
    - tlsNegotiatedProtocol :: Maybe ByteString
    - tlsChiperID :: Word16
    - tlsClientCertificate :: Maybe CertificateChain
    }
  - | QUIC {
    - quicNegotiatedProtocol :: Maybe ByteString
    - quicChiperID :: Word16
    - quicClientCertificate :: Maybe CertificateChain
    }
- data Connection = Connection {
  - connSendMany :: [ByteString] -> IO ()
  - connSendAll :: ByteString -> IO ()
  - connSendFile :: SendFile
  - connClose :: IO ()
  - connRecv :: Recv
  - connRecvBuf :: RecvBuf
  - connWriteBuffer :: IORef WriteBuffer
  - connHTTP2 :: IORef Bool
  - connMySockAddr :: SockAddr
  }
- socketConnection :: Settings -> Socket -> IO Connection
- type Recv = IO ByteString
- type RecvBuf = Buffer -> BufSize -> IO Bool
- type Buffer = Ptr Word8
- type BufSize = Int
- data WriteBuffer = WriteBuffer {
  - bufBuffer :: Buffer
  - bufSize :: !BufSize
  - bufFree :: IO ()
  }
- createWriteBuffer :: BufSize -> IO WriteBuffer
- allocateBuffer :: Int -> IO Buffer
- freeBuffer :: Buffer -> IO ()
- copy :: Buffer -> ByteString -> IO Buffer
- data FileId = FileId {
  - fileIdPath :: FilePath
  - fileIdFd :: Maybe Fd
  }
- type SendFile = FileId -> Integer -> Integer -> IO () -> [ByteString] -> IO ()
- sendFile :: Socket -> Buffer -> BufSize -> (ByteString -> IO ()) -> SendFile
- readSendFile :: Buffer -> BufSize -> (ByteString -> IO ()) -> SendFile
- warpVersion :: String
- data InternalInfo = InternalInfo {
  - timeoutManager :: Manager
  - getDate :: IO GMTDate
  - getFd :: FilePath -> IO (Maybe Fd, Refresh)
  - getFileInfo :: FilePath -> IO FileInfo
  }
- type HeaderValue = ByteString
- type IndexedHeader = Array Int (Maybe HeaderValue)
- requestMaxIndex :: Int
- module System.TimeManager
- openFile :: FilePath -> IO Fd
- data Fd
- closeFile :: Fd -> IO ()
- withFdCache :: Int -> ((FilePath -> IO (Maybe Fd, Refresh)) -> IO a) -> IO a
- type Refresh = IO ()
- setFileCloseOnExec :: Fd -> IO ()
- data FileInfo = FileInfo {
  - fileInfoName :: !FilePath
  - fileInfoSize :: !Integer
  - fileInfoTime :: HTTPDate
  - fileInfoDate :: ByteString
  }
- withFileInfoCache :: Int -> ((FilePath -> IO FileInfo) -> IO a) -> IO a
- getInfo :: FilePath -> IO FileInfo
- withDateCache :: (IO GMTDate -> IO a) -> IO a
- type GMTDate = ByteString
- data Source
- data FirstRequest
  - = FirstRequest
  - | SubsequentRequest
- recvRequest :: FirstRequest -> Settings -> Connection -> InternalInfo -> Handle -> SockAddr -> Source -> Transport -> IO (Request, Maybe (IORef Int), IndexedHeader, IO ByteString)
- sendResponse :: Settings -> Connection -> InternalInfo -> Handle -> Request -> IndexedHeader -> IO ByteString -> Response -> IO Bool
- setSocketCloseOnExec :: Socket -> IO ()
- windowsThreadBlockHack :: IO a -> IO a
- http2server :: String -> Settings -> InternalInfo -> Transport -> SockAddr -> Application -> Server
- withII :: Settings -> (InternalInfo -> IO a) -> IO a
- serveConnection :: Connection -> InternalInfo -> Handle -> SockAddr -> Transport -> Settings -> Application -> IO ()
- pReadMaker :: InternalInfo -> PositionReadMaker

# Settings

data 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

Settings |
Fields settingsPort :: Port Port to listen on. Default value: 3000 settingsHost :: HostPreference Default value: HostIPv4 settingsOnException :: Maybe Request -> SomeException -> IO () What to do with exceptions thrown by either the application or server. Default: ignore server-generated exceptions (see `InvalidRequest`) and print application-generated applications to stderr. settingsOnExceptionResponse :: SomeException -> Response A function to create `Response` when an exception occurs. Default: 500, text/plain, "Something went wrong" Since 2.0.3 settingsOnOpen :: SockAddr -> IO Bool What to do when a connection is open. When `False` is returned, the connection is closed immediately. Otherwise, the connection is going on. Default: always returns `True`. settingsOnClose :: SockAddr -> IO () What to do when a connection is close. Default: do nothing. settingsTimeout :: Int Timeout value in seconds. Default value: 30 settingsManager :: Maybe Manager Use an existing timeout manager instead of spawning a new one. If used, `settingsTimeout` is ignored. Default is `Nothing` settingsFdCacheDuration :: Int Cache duration time of file descriptors in seconds. 0 means that the cache mechanism is not used. Default value: 0 settingsFileInfoCacheDuration :: Int Cache duration time of file information in seconds. 0 means that the cache mechanism is not used. Default value: 0 settingsBeforeMainLoop :: IO () Code to run after the listening socket is ready but before entering the main event loop. Useful for signaling to tests that they can start running, or to drop permissions after binding to a restricted port. Default: do nothing. Since 1.3.6 settingsFork :: ((forall a. IO a -> IO a) -> IO ()) -> IO () Code to fork a new thread to accept a connection. This may be useful if you need OS bound threads, or if you wish to develop an alternative threading model. Default: `defaultFork` Since 3.0.4 settingsAccept :: Socket -> IO (Socket, SockAddr) Code to accept a new connection. Useful if you need to provide connected sockets from something other than a standard accept call. Default: `defaultAccept` Since 3.3.24 settingsNoParsePath :: Bool Perform no parsing on the rawPathInfo. This is useful for writing HTTP proxies. Default: False Since 2.0.3 settingsInstallShutdownHandler :: IO () -> IO () An action to install a handler (e.g. Unix signal handler) to close a listen socket. The first argument is an action to close the listen socket. Default: no action Since 3.0.1 settingsServerName :: ByteString Default server name if application does not set one. Since 3.0.2 settingsMaximumBodyFlush :: Maybe Int See `setMaximumBodyFlush`. Since 3.0.3 settingsProxyProtocol :: ProxyProtocol Specify usage of the PROXY protocol. Since 3.0.5 settingsSlowlorisSize :: Int Size of bytes read to prevent Slowloris protection. Default value: 2048 Since 3.1.2 settingsHTTP2Enabled :: Bool Whether to enable HTTP2 ALPN/upgrades. Default: True Since 3.1.7 settingsLogger :: Request -> Status -> Maybe Integer -> IO () A log function. Default: no action. Since 3.1.10 settingsServerPushLogger :: Request -> ByteString -> Integer -> IO () A HTTP/2 server push log function. Default: no action. Since 3.2.7 settingsGracefulShutdownTimeout :: Maybe Int An optional timeout to limit the time (in seconds) waiting for a graceful shutdown of the web server. Since 3.2.8 settingsGracefulCloseTimeout1 :: Int A timeout to limit the time (in milliseconds) waiting for FIN for HTTP/1.x. 0 means uses immediate close. Default: 0. Since 3.3.5 settingsGracefulCloseTimeout2 :: Int A timeout to limit the time (in milliseconds) waiting for FIN for HTTP/2. 0 means uses immediate close. Default: 2000. Since 3.3.5 settingsMaxTotalHeaderLength :: Int Determines the maximum header size that Warp will tolerate when using HTTP/1.x. Since 3.3.8 settingsAltSvc :: Maybe ByteString Specify the header value of Alternative Services (AltSvc:). Default: Nothing Since 3.3.11 settingsMaxBuilderResponseBufferSize :: Int Determines the maxium buffer size when sending `Builder` responses (See `responseBuilder`). When sending a builder response warp uses a 16 KiB buffer to write the builder to. When that buffer is too small to fit the builder warp will free it and create a new one that will fit the builder. To protect against allocating too large a buffer warp will error if the builder requires more than this maximum. Default: 1049_000_000 = 1 MiB. Since 3.3.22

data ProxyProtocol #

Specify usage of the PROXY protocol.

Constructors

ProxyProtocolNone | See `setProxyProtocolNone`.
ProxyProtocolRequired | See `setProxyProtocolRequired`.
ProxyProtocolOptional | See `setProxyProtocolOptional`.

# Low level run functions

runSettingsConnection :: Settings -> IO (Connection, SockAddr) -> Application -> IO () #

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

runSettingsConnectionMaker :: Settings -> IO (IO Connection, SockAddr) -> Application -> IO () #

This modifies the connection maker so that it returns `TCP` for `Transport` (i.e. plain HTTP) then calls `runSettingsConnectionMakerSecure`.

runSettingsConnectionMakerSecure :: Settings -> IO (IO (Connection, Transport), SockAddr) -> Application -> IO () #

The core run function which takes `Settings`, a connection maker and `Application`. The connection maker can return a connection of either plain HTTP or HTTP over TLS.

Since 2.1.4

data Transport #

What kind of transport is used for this connection?

Constructors

TCP | Plain channel: TCP
TLS |
Fields tlsMajorVersion :: Int tlsMinorVersion :: Int tlsNegotiatedProtocol :: Maybe ByteString The result of Application Layer Protocol Negociation in RFC 7301 tlsChiperID :: Word16 Encrypted channel: TLS or SSL tlsClientCertificate :: Maybe CertificateChain
QUIC |
Fields quicNegotiatedProtocol :: Maybe ByteString quicChiperID :: Word16 quicClientCertificate :: Maybe CertificateChain

# Connection

data Connection #

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

Constructors

Connection |
Fields connSendMany :: [ByteString] -> IO () This is not used at this moment. connSendAll :: ByteString -> IO () The sending function. connSendFile :: SendFile The sending function for files in HTTP/1.1. connClose :: IO () The connection closing function. Warp guarantees it will only be called once. Other functions (like `connRecv`) may be called after `connClose` is called. connRecv :: Recv The connection receiving function. This returns "" for EOF or exceptions. connRecvBuf :: RecvBuf Obsoleted. connWriteBuffer :: IORef WriteBuffer Reference to a write buffer. When during sending of a `Builder` response it's detected the current `WriteBuffer` is too small it will be freed and a new bigger buffer will be created and written to this reference. connHTTP2 :: IORef Bool Is this connection HTTP/2? connMySockAddr :: SockAddr

socketConnection :: Settings -> Socket -> IO Connection #

Creating `Connection` for plain HTTP based on a given socket.

## Receive

type Recv = IO ByteString #

Type for the receiving function with a buffer pool.

type RecvBuf = Buffer -> BufSize -> IO Bool #

## Buffer

type Buffer = Ptr Word8 #

Type for buffer.

type BufSize = Int #

Type for buffer size.

data WriteBuffer #

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

Constructors

WriteBuffer |
Fields bufBuffer :: Buffer bufSize :: !BufSize The size of the write buffer. bufFree :: IO () Free the allocated buffer. Warp guarantees it will only be called once, and no other functions will be called after it.

createWriteBuffer :: BufSize -> IO WriteBuffer #

Allocate a buffer of the given size and wrap it in a `WriteBuffer` containing that size and a finalizer.

allocateBuffer :: Int -> IO Buffer #

Allocating a buffer with malloc().

freeBuffer :: Buffer -> IO () #

Releasing a buffer with free().

copy :: Buffer -> ByteString -> IO Buffer #

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

## Sendfile

data FileId #

Data type to abstract file identifiers. On Unix, a file descriptor would be specified to make use of the file descriptor cache.

Since: 3.1.0

Constructors

FileId |
Fields fileIdPath :: FilePath fileIdFd :: Maybe Fd

type SendFile = FileId -> Integer -> Integer -> IO () -> [ByteString] -> IO () #

fileid, offset, length, hook action, HTTP headers

Since: 3.1.0

sendFile :: Socket -> Buffer -> BufSize -> (ByteString -> IO ()) -> SendFile #

Function to send a file based on sendfile() for Linux/Mac/FreeBSD. This makes use of the file descriptor cache. For other OSes, this is identical to `readSendFile`.

Since: 3.1.0

readSendFile :: 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

warpVersion :: String #

The version of Warp.

# Data types

data InternalInfo #

Constructors

InternalInfo |
Fields timeoutManager :: Manager getDate :: IO GMTDate getFd :: FilePath -> IO (Maybe Fd, Refresh) getFileInfo :: FilePath -> IO FileInfo

type HeaderValue = ByteString #

The type for header value used with `HeaderName`.

type IndexedHeader = Array Int (Maybe HeaderValue) #

Array for a set of HTTP headers.

requestMaxIndex :: 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

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.

module System.TimeManager

# File descriptor cache

openFile :: FilePath -> IO Fd #

data Fd #

#### Instances

Instances details

Bits Fd |
Instance details Defined in GHC.Internal.System.Posix.Types Methods (.&.) :: Fd -> Fd -> Fd # (.|.) :: Fd -> Fd -> Fd # xor :: Fd -> Fd -> Fd # complement :: Fd -> Fd # shift :: Fd -> Int -> Fd # rotate :: Fd -> Int -> Fd # zeroBits :: Fd # bit :: Int -> Fd # setBit :: Fd -> Int -> Fd # clearBit :: Fd -> Int -> Fd # complementBit :: Fd -> Int -> Fd # testBit :: Fd -> Int -> Bool # bitSizeMaybe :: Fd -> Maybe Int # bitSize :: Fd -> Int # isSigned :: Fd -> Bool # shiftL :: Fd -> Int -> Fd # unsafeShiftL :: Fd -> Int -> Fd # shiftR :: Fd -> Int -> Fd # unsafeShiftR :: Fd -> Int -> Fd # rotateL :: Fd -> Int -> Fd # rotateR :: Fd -> Int -> Fd # popCount :: Fd -> Int #
FiniteBits Fd |
Instance details Defined in GHC.Internal.System.Posix.Types Methods finiteBitSize :: Fd -> Int # countLeadingZeros :: Fd -> Int # countTrailingZeros :: Fd -> Int #
Bounded Fd |
Instance details Defined in GHC.Internal.System.Posix.Types Methods minBound :: Fd # maxBound :: Fd #
Enum Fd |
Instance details Defined in GHC.Internal.System.Posix.Types Methods succ :: Fd -> Fd # pred :: Fd -> Fd # toEnum :: Int -> Fd # fromEnum :: Fd -> Int # enumFrom :: Fd -> [Fd] # enumFromThen :: Fd -> Fd -> [Fd] # enumFromTo :: Fd -> Fd -> [Fd] # enumFromThenTo :: Fd -> Fd -> Fd -> [Fd] #
Storable Fd |
Instance details Defined in GHC.Internal.System.Posix.Types Methods sizeOf :: Fd -> Int # alignment :: Fd -> Int # peekElemOff :: Ptr Fd -> Int -> IO Fd # pokeElemOff :: Ptr Fd -> Int -> Fd -> IO () # peekByteOff :: Ptr b -> Int -> IO Fd # pokeByteOff :: Ptr b -> Int -> Fd -> IO () # peek :: Ptr Fd -> IO Fd # poke :: Ptr Fd -> Fd -> IO () #
Ix Fd |
Instance details Defined in GHC.Internal.System.Posix.Types Methods range :: (Fd, Fd) -> [Fd] # index :: (Fd, Fd) -> Fd -> Int # unsafeIndex :: (Fd, Fd) -> Fd -> Int # inRange :: (Fd, Fd) -> Fd -> Bool # rangeSize :: (Fd, Fd) -> Int # unsafeRangeSize :: (Fd, Fd) -> Int #
Num Fd |
Instance details Defined in GHC.Internal.System.Posix.Types Methods (+) :: Fd -> Fd -> Fd # (-) :: Fd -> Fd -> Fd # (*) :: Fd -> Fd -> Fd # negate :: Fd -> Fd # abs :: Fd -> Fd # signum :: Fd -> Fd # fromInteger :: Integer -> Fd #
Read Fd |
Instance details Defined in GHC.Internal.System.Posix.Types Methods readsPrec :: Int -> ReadS Fd # readList :: ReadS [Fd] # readPrec :: ReadPrec Fd # readListPrec :: ReadPrec [Fd] #
Integral Fd |
Instance details Defined in GHC.Internal.System.Posix.Types Methods quot :: Fd -> Fd -> Fd # rem :: Fd -> Fd -> Fd # div :: Fd -> Fd -> Fd # mod :: Fd -> Fd -> Fd # quotRem :: Fd -> Fd -> (Fd, Fd) # divMod :: Fd -> Fd -> (Fd, Fd) # toInteger :: Fd -> Integer #
Real Fd |
Instance details Defined in GHC.Internal.System.Posix.Types Methods toRational :: Fd -> Rational #
Show Fd |
Instance details Defined in GHC.Internal.System.Posix.Types Methods showsPrec :: Int -> Fd -> ShowS # show :: Fd -> String # showList :: [Fd] -> ShowS #
Eq Fd |
Instance details Defined in GHC.Internal.System.Posix.Types Methods (==) :: Fd -> Fd -> Bool # (/=) :: Fd -> Fd -> Bool #
Ord Fd |
Instance details Defined in GHC.Internal.System.Posix.Types Methods compare :: Fd -> Fd -> Ordering # (<) :: Fd -> Fd -> Bool # (<=) :: Fd -> Fd -> Bool # (>) :: Fd -> Fd -> Bool # (>=) :: Fd -> Fd -> Bool # max :: Fd -> Fd -> Fd # min :: Fd -> Fd -> Fd #

closeFile :: Fd -> IO () #

withFdCache :: 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 second.

type Refresh = IO () #

An action to activate a Fd cache entry.

setFileCloseOnExec :: Fd -> IO () #

# File information cache

data FileInfo #

File information.

Constructors

FileInfo |
Fields fileInfoName :: !FilePath fileInfoSize :: !Integer fileInfoTime :: HTTPDate Modification time fileInfoDate :: ByteString Modification time in the GMT format

#### Instances

Instances details

Show FileInfo # |
Instance details Defined in Network.Wai.Handler.Warp.FileInfoCache Methods showsPrec :: Int -> FileInfo -> ShowS # show :: FileInfo -> String # showList :: [FileInfo] -> ShowS #
Eq FileInfo # |
Instance details Defined in Network.Wai.Handler.Warp.FileInfoCache Methods (==) :: FileInfo -> FileInfo -> Bool # (/=) :: FileInfo -> FileInfo -> Bool #

withFileInfoCache :: 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 second.

getInfo :: FilePath -> IO FileInfo #

Getting the file information corresponding to the file.

# Date

withDateCache :: (IO GMTDate -> IO a) -> IO a #

Creating `DateCache` and executing the action.

type GMTDate = ByteString #

The type of the Date header value.

# Request and response

data Source #

Type for input streaming.

data FirstRequest #

first request on this connection?

Constructors

FirstRequest |
SubsequentRequest |

recvRequest #

Arguments

:: FirstRequest |
-> Settings |
-> Connection |
-> InternalInfo |
-> Handle |
-> SockAddr | Peer's address.
-> Source | Where HTTP request comes from.
-> Transport |
-> IO (Request, Maybe (IORef Int), IndexedHeader, 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`.

sendResponse #

Arguments

:: Settings |
-> Connection |
-> InternalInfo |
-> Handle |
-> Request | HTTP request.
-> IndexedHeader | Indexed header of HTTP request.
-> IO ByteString | source from client, for raw response
-> Response | HTTP response including status code and response header.
-> 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

setSocketCloseOnExec :: Socket -> IO () #

Set flag FileCloseOnExec flag on a socket (on Unix)

Copied from: https://github.com/mzero/plush/blob/master/src/Plush/Server/Warp.hs

Since: 3.2.17

windowsThreadBlockHack :: IO a -> IO a #

# Misc

http2server :: String -> Settings -> InternalInfo -> Transport -> SockAddr -> Application -> Server #

Converting WAI application to the server type of http2 library.

Since 3.3.11

withII :: Settings -> (InternalInfo -> IO a) -> IO a #

Running an action with internal info.

Since 3.3.11

serveConnection :: Connection -> InternalInfo -> Handle -> SockAddr -> Transport -> Settings -> Application -> IO () #

pReadMaker :: InternalInfo -> PositionReadMaker #

`PositionReadMaker` based on file descriptor cache.

Since 3.3.13