-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A fast, light-weight web server for WAI applications. -- -- API docs and the README are available at -- http://www.stackage.org/package/warp. @package warp @version 3.0.13 module Network.Wai.Handler.Warp.Buffer type Buffer = Ptr Word8 type BufSize = Int bufferSize :: BufSize allocateBuffer :: Int -> IO Buffer freeBuffer :: Buffer -> IO () toBlazeBuffer :: Buffer -> BufSize -> IO Buffer -- | In order to provide slowloris protection, Warp provides timeout -- handlers. We follow these rules: -- -- module Network.Wai.Handler.Warp.Timeout -- | A timeout manager type Manager = Reaper [Handle] Handle -- | An action to be performed on timeout. type TimeoutAction = IO () -- | A handle used by Manager data Handle -- | Creating timeout manager which works every N micro seconds where N is -- the first argument. initialize :: Int -> IO Manager -- | Stopping timeout manager. stopManager :: Manager -> IO () -- | Call the inner function with a timeout manager. withManager :: Int -> (Manager -> IO a) -> IO a -- | Registering a timeout action. register :: Manager -> TimeoutAction -> IO Handle -- | Registering a timeout action of killing this thread. registerKillThread :: Manager -> IO Handle -- | Setting the state to active. Manager turns active to inactive -- repeatedly. tickle :: Handle -> IO () -- | Setting the state to canceled. Manager eventually removes this -- without timeout action. cancel :: Handle -> IO () -- | Setting the state to paused. Manager does not change the value. pause :: Handle -> IO () -- | Setting the paused state to active. This is an alias to tickle. resume :: Handle -> IO () data TimeoutThread [TimeoutThread] :: TimeoutThread instance Exception TimeoutThread instance Show TimeoutThread module Network.Wai.Handler.Warp.Internal -- | 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
--   
data Settings [Settings] :: Int -> HostPreference -> (Maybe Request -> SomeException -> IO ()) -> (SomeException -> Response) -> (SockAddr -> IO Bool) -> (SockAddr -> IO ()) -> Int -> Maybe Manager -> Int -> IO () -> (((forall a. IO a -> IO a) -> IO ()) -> IO ()) -> Bool -> (IO () -> IO ()) -> ByteString -> Maybe Int -> ProxyProtocol -> Settings -- | Port to listen on. Default value: 3000 -- | Deprecated: Use setPort instead [settingsPort] :: Settings -> Int -- | Default value: HostIPv4 -- | Deprecated: Use setHost instead [settingsHost] :: Settings -> HostPreference -- | 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. -- | Deprecated: Use setOnException instead [settingsOnException] :: Settings -> Maybe Request -> SomeException -> IO () -- | A function to create Response when an exception occurs. -- -- Default: 500, text/plain, "Something went wrong" -- -- Since 2.0.3 -- | Deprecated: Use setOnExceptionResponse instead [settingsOnExceptionResponse] :: Settings -> SomeException -> Response -- | 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. -- | Deprecated: Use setOnOpen instead [settingsOnOpen] :: Settings -> SockAddr -> IO Bool -- | What to do when a connection is close. Default: do nothing. -- | Deprecated: Use setOnClose instead [settingsOnClose] :: Settings -> SockAddr -> IO () -- | Timeout value in seconds. Default value: 30 -- | Deprecated: Use setTimeout instead [settingsTimeout] :: Settings -> Int -- | Use an existing timeout manager instead of spawning a new one. If -- used, settingsTimeout is ignored. Default is Nothing -- | Deprecated: Use setManager instead [settingsManager] :: Settings -> Maybe Manager -- | Cache duratoin time of file descriptors in seconds. 0 means that the -- cache mechanism is not used. Default value: 0 -- | Deprecated: Use setFdCacheDuration instead [settingsFdCacheDuration] :: Settings -> Int -- | 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 -- | Deprecated: Use setBeforeMainLoop instead [settingsBeforeMainLoop] :: Settings -> 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: void . forkIOWithUnmask -- -- Since 3.0.4 [settingsFork] :: Settings -> ((forall a. IO a -> IO a) -> IO ()) -> IO () -- | Perform no parsing on the rawPathInfo. -- -- This is useful for writing HTTP proxies. -- -- Default: False -- -- Since 2.0.3 -- | Deprecated: Use setNoParsePath instead [settingsNoParsePath] :: Settings -> Bool [settingsInstallShutdownHandler] :: Settings -> IO () -> IO () -- | Default server name if application does not set one. -- -- Since 3.0.2 [settingsServerName] :: Settings -> ByteString -- | See setMaximumBodyFlush. -- -- Since 3.0.3 [settingsMaximumBodyFlush] :: Settings -> Maybe Int -- | Specify usage of the PROXY protocol. -- -- Since 3.0.5. [settingsProxyProtocol] :: Settings -> ProxyProtocol getOnOpen :: Settings -> SockAddr -> IO Bool getOnClose :: Settings -> SockAddr -> IO () getOnException :: Settings -> Maybe Request -> SomeException -> IO () -- | A fast, light-weight HTTP server handler for WAI. -- -- Note on slowloris timeouts: to prevent slowloris attacks, timeouts are -- used at various points in request receiving and response sending. One -- interesting corner case is partial request body consumption; in that -- case, Warp's timeout handling is still in effect, and the timeout will -- not be triggered again. Therefore, it is recommended that once you -- start consuming the request body, you either: -- -- -- -- For more information, see -- https://github.com/yesodweb/wai/issues/351. module Network.Wai.Handler.Warp -- | Run an Application on the given port. This calls -- runSettings with defaultSettings. run :: Port -> Application -> IO () -- | Run an Application on the port present in the PORT -- environment variable -- -- Uses the Port given when the variable is unset. -- -- Since 3.0.9 runEnv :: Port -> Application -> IO () -- | Run an Application with the given Settings. runSettings :: Settings -> Application -> IO () -- | Same as runSettings, but uses a user-supplied socket instead of -- opening one. This allows the user to provide, for example, Unix named -- socket, which can be used when reverse HTTP proxying into your -- application. -- -- Note that the settingsPort will still be passed to -- Applications via the serverPort record. -- -- When the listen socket in the second argument is closed, all live -- connections are gracefully shut down. runSettingsSocket :: Settings -> Socket -> Application -> IO () -- | Allows you to provide a function which will return a -- Connection. In cases where creating the Connection can -- be expensive, this allows the expensive computations to be performed -- in a separate thread instead of the main server loop. -- -- Since 1.3.5 runSettingsConnection :: Settings -> IO (Connection, SockAddr) -> Application -> IO () runSettingsConnectionMaker :: Settings -> IO (IO Connection, SockAddr) -> Application -> IO () -- | Allows you to provide a function which will return a function which -- will return Connection. -- -- Since 2.1.4 runSettingsConnectionMakerSecure :: Settings -> IO (IO (Connection, Transport), SockAddr) -> Application -> IO () -- | 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
--   
data Settings -- | The default settings for the Warp server. See the individual settings -- for the default value. defaultSettings :: Settings -- | Port to listen on. Default value: 3000 -- -- Since 2.1.0 setPort :: Int -> Settings -> Settings -- | Interface to bind to. Default value: HostIPv4 -- -- Since 2.1.0 setHost :: HostPreference -> Settings -> Settings -- | What to do with exceptions thrown by either the application or server. -- Default: ignore server-generated exceptions (see -- InvalidRequest) and print application-generated exceptions to -- stderr. -- -- Since 2.1.0 setOnException :: (Maybe Request -> SomeException -> IO ()) -> Settings -> Settings -- | A function to create a Response when an exception occurs. -- -- Default: 500, text/plain, "Something went wrong" -- -- Since 2.1.0 setOnExceptionResponse :: (SomeException -> Response) -> Settings -> Settings -- | What to do when a connection is opened. When False is returned, -- the connection is closed immediately. Otherwise, the connection is -- going on. Default: always returns True. -- -- Since 2.1.0 setOnOpen :: (SockAddr -> IO Bool) -> Settings -> Settings -- | What to do when a connection is closed. Default: do nothing. -- -- Since 2.1.0 setOnClose :: (SockAddr -> IO ()) -> Settings -> Settings -- | Timeout value in seconds. Default value: 30 -- -- Since 2.1.0 setTimeout :: Int -> Settings -> Settings -- | Use an existing timeout manager instead of spawning a new one. If -- used, settingsTimeout is ignored. -- -- Since 2.1.0 setManager :: Manager -> Settings -> Settings -- | Cache duration time of file descriptors in seconds. 0 means that the -- cache mechanism is not used. -- -- The FD cache is an optimization that is useful for servers dealing -- with static files. However, if files are being modified, it can cause -- incorrect results in some cases. Therefore, we disable it by default. -- If you know that your files will be static or you prefer performance -- to file consistency, it's recommended to turn this on; a reasonable -- value for those cases is 10. Enabling this cache results in drastic -- performance improvement for file transfers. -- -- Default value: since 3.0.13, default value is 0, was previously 10 setFdCacheDuration :: Int -> Settings -> Settings -- | 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 2.1.0 setBeforeMainLoop :: IO () -> Settings -> Settings -- | Perform no parsing on the rawPathInfo. -- -- This is useful for writing HTTP proxies. -- -- Default: False -- -- Since 2.1.0 setNoParsePath :: Bool -> Settings -> Settings -- | A code to install shutdown handler. -- -- For instance, this code should set up a UNIX signal handler. The -- handler should call the first argument, which close the listen socket, -- at shutdown. -- -- Default: does not install any code. -- -- Since 3.0.1 setInstallShutdownHandler :: (IO () -> IO ()) -> Settings -> Settings -- | Default server name if application does not set one. -- -- Since 3.0.2 setServerName :: ByteString -> Settings -> Settings -- | The maximum number of bytes to flush from an unconsumed request body. -- -- By default, Warp does not flush the request body so that, if a large -- body is present, the connection is simply terminated instead of -- wasting time and bandwidth on transmitting it. However, some clients -- do not deal with that situation well. You can either change this -- setting to Nothing to flush the entire body in all cases, or -- in your application ensure that you always consume the entire request -- body. -- -- Default: 8192 bytes. -- -- Since 3.0.3 setMaximumBodyFlush :: Maybe Int -> Settings -> Settings -- | 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: void . forkIOWithUnmask -- -- Since 3.0.4 setFork :: (((forall a. IO a -> IO a) -> IO ()) -> IO ()) -> Settings -> Settings -- | Do not use the PROXY protocol. -- -- Since 3.0.5 setProxyProtocolNone :: Settings -> Settings -- | Require PROXY header. -- -- This is for cases where a "dumb" TCP/SSL proxy is being used, which -- cannot add an X-Forwarded-For HTTP header field but has -- enabled support for the PROXY protocol. -- -- See http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt -- and -- http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/TerminologyandKeyConcepts.html#proxy-protocol. -- -- Only the human-readable header format (version 1) is supported. The -- binary header format (version 2) is not supported. -- -- Since 3.0.5 setProxyProtocolRequired :: Settings -> Settings -- | Use the PROXY header if it exists, but also accept connections without -- the header. See setProxyProtocolRequired. -- -- WARNING: This is contrary to the PROXY protocol specification and -- using it can indicate a security problem with your architecture if the -- web server is directly accessable to the public, since it would allow -- easy IP address spoofing. However, it can be useful in some cases, -- such as if a load balancer health check uses regular HTTP without the -- PROXY header, but proxied connections do include the PROXY -- header. -- -- Since 3.0.5 setProxyProtocolOptional :: Settings -> Settings -- | Get the listening port. -- -- Since 2.1.1 getPort :: Settings -> Int -- | Get the interface to bind to. -- -- Since 2.1.1 getHost :: Settings -> HostPreference -- | Port to listen on. Default value: 3000 -- | Deprecated: Use setPort instead settingsPort :: Settings -> Int -- | Default value: HostIPv4 -- | Deprecated: Use setHost instead settingsHost :: Settings -> HostPreference -- | 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. -- | Deprecated: Use setOnException instead settingsOnException :: Settings -> Maybe Request -> SomeException -> IO () -- | A function to create Response when an exception occurs. -- -- Default: 500, text/plain, "Something went wrong" -- -- Since 2.0.3 -- | Deprecated: Use setOnExceptionResponse instead settingsOnExceptionResponse :: Settings -> SomeException -> Response -- | 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. -- | Deprecated: Use setOnOpen instead settingsOnOpen :: Settings -> SockAddr -> IO Bool -- | What to do when a connection is close. Default: do nothing. -- | Deprecated: Use setOnClose instead settingsOnClose :: Settings -> SockAddr -> IO () -- | Timeout value in seconds. Default value: 30 -- | Deprecated: Use setTimeout instead settingsTimeout :: Settings -> Int -- | Use an existing timeout manager instead of spawning a new one. If -- used, settingsTimeout is ignored. Default is Nothing -- | Deprecated: Use setManager instead settingsManager :: Settings -> Maybe Manager -- | Cache duratoin time of file descriptors in seconds. 0 means that the -- cache mechanism is not used. Default value: 0 -- | Deprecated: Use setFdCacheDuration instead settingsFdCacheDuration :: Settings -> Int -- | 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 -- | Deprecated: Use setBeforeMainLoop instead settingsBeforeMainLoop :: Settings -> IO () -- | Perform no parsing on the rawPathInfo. -- -- This is useful for writing HTTP proxies. -- -- Default: False -- -- Since 2.0.3 -- | Deprecated: Use setNoParsePath instead settingsNoParsePath :: Settings -> Bool -- | Default implementation of settingsOnExceptionResponse for the -- debugging purpose. 500, text/plain, a showed exception. exceptionResponseForDebug :: SomeException -> Response -- | Apply the logic provided by defaultExceptionHandler to -- determine if an exception should be shown or not. The goal is to hide -- exceptions which occur under the normal course of the web server -- running. -- -- Since 2.1.3 defaultShouldDisplayException :: SomeException -> Bool -- | What kind of transport is used for this connection? data Transport -- | Plain channel: TCP [TCP] :: Transport -- | Encrypted channel: TLS or SSL [TLS] :: Int -> Int -> Maybe ByteString -> Word16 -> Transport [tlsMajorVersion] :: Transport -> Int [tlsMinorVersion] :: Transport -> Int -- | The result of Application Layer Protocol Negociation in RFC 7301 [tlsNegotiatedProtocol] :: Transport -> Maybe ByteString [tlsChiperID] :: Transport -> Word16 data HostPreference :: * -- | TCP port number. type Port = Int -- | Error types for bad Request. data InvalidRequest [NotEnoughLines] :: [String] -> InvalidRequest [BadFirstLine] :: String -> InvalidRequest [NonHttp] :: InvalidRequest [IncompleteHeaders] :: InvalidRequest [ConnectionClosedByPeer] :: InvalidRequest [OverLargeHeader] :: InvalidRequest [BadProxyHeader] :: String -> InvalidRequest -- | Whether or not ConnSendFileOverride in Connection can be -- overridden. This is a kind of hack to keep the signature of -- Connection clean. data ConnSendFileOverride -- | Don't override [NotOverride] :: ConnSendFileOverride -- | Override with this Socket [Override] :: Socket -> ConnSendFileOverride -- | Explicitly pause the slowloris timeout. -- -- This is useful for cases where you partially consume a request body. -- For more information, see -- https://github.com/yesodweb/wai/issues/351 -- -- Since 3.0.10 pauseTimeout :: Request -> IO () -- | Data type to manipulate IO actions for connections. data Connection [Connection] :: ([ByteString] -> IO ()) -> (ByteString -> IO ()) -> (FilePath -> Integer -> Integer -> IO () -> [ByteString] -> IO ()) -> IO () -> IO ByteString -> Buffer -> Buffer -> BufSize -> ConnSendFileOverride -> Connection [connSendMany] :: Connection -> [ByteString] -> IO () [connSendAll] :: Connection -> ByteString -> IO () -- | filepath, offset, length, hook action, HTTP headers [connSendFile] :: Connection -> FilePath -> Integer -> Integer -> IO () -> [ByteString] -> IO () [connClose] :: Connection -> IO () [connRecv] :: Connection -> IO ByteString [connReadBuffer] :: Connection -> Buffer [connWriteBuffer] :: Connection -> Buffer [connBufferSize] :: Connection -> BufSize [connSendFileOverride] :: Connection -> ConnSendFileOverride -- | Default action value for Connection. socketConnection :: Socket -> IO Connection -- | The version of Warp. warpVersion :: String -- | Internal information. data InternalInfo [InternalInfo] :: Handle -> Maybe MutableFdCache -> DateCache -> InternalInfo [threadHandle] :: InternalInfo -> Handle [fdCacher] :: InternalInfo -> Maybe MutableFdCache [dateCacher] :: InternalInfo -> DateCache -- | The type for header value used with HeaderName. type HeaderValue = ByteString -- | Array for a set of HTTP headers. type IndexedHeader = Array Int (Maybe HeaderValue) -- | The size for IndexedHeader for HTTP Request. From 0 to this -- corresponds to "Content-Length", "Transfer-Encoding", "Expect", -- "Connection", "Range", and "Host". requestMaxIndex :: Int -- | Creating MutableFdCache and executing the action in the second -- argument. The first argument is a cache duration in second. withFdCache :: Int -> (Maybe MutableFdCache -> IO a) -> IO a -- | Getting Fd and Refresh from the mutable Fd cacher. getFd :: MutableFdCache -> FilePath -> IO (Fd, Refresh) -- | Mutable Fd cacher. type MutableFdCache = Reaper FdCache (Hash, FdEntry) -- | An action to activate a Fd cache entry. type Refresh = IO () -- | Creating DateCache and executing the action. withDateCache :: (DateCache -> IO a) -> IO a -- | Getting GMTDate based on DateCache. getDate :: DateCache -> IO GMTDate -- | The type of the cache of the Date header value. type DateCache = IO GMTDate -- | The type of the Date header value. type GMTDate = ByteString -- | Receiving a HTTP request from Connection and parsing its header -- to create Request. recvRequest :: Settings -> Connection -> InternalInfo -> SockAddr -> Source -> IO (Request, Maybe (IORef Int), IndexedHeader, IO ByteString) -- | Sending a HTTP response to Connection according to -- Response. -- -- Applications/middlewares MUST specify a proper ResponseHeaders. -- so that inconsistency does not happen. No header is deleted by this -- function. -- -- Especially, Applications/middlewares MUST take care of 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: -- -- sendResponse :: ByteString -> Connection -> InternalInfo -> Request -> IndexedHeader -> IO ByteString -> Response -> IO Bool