{-# LANGUAGE CPP #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE PatternGuards #-}
{-# OPTIONS_GHC -fno-warn-deprecations #-}

---------------------------------------------------------
--
-- Module        : Network.Wai.Handler.Warp
-- Copyright     : Michael Snoyman
-- License       : BSD3
--
-- Maintainer    : Michael Snoyman <michael@snoyman.com>
-- Stability     : Stable
-- Portability   : portable
--
-- A fast, light-weight HTTP server handler for WAI.
--
---------------------------------------------------------

-- | A fast, light-weight HTTP server handler for WAI.
--
-- HTTP\/1.0, HTTP\/1.1 and HTTP\/2 are supported. For HTTP\/2,
-- Warp supports direct and ALPN (in TLS) but not upgrade.
--
-- 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:
--
-- * consume the entire body promptly
--
-- * call the 'pauseTimeout' function
--
-- For more information, see <https://github.com/yesodweb/wai/issues/351>.
--
--
module Network.Wai.Handler.Warp (
    -- * Run a Warp server
    -- | All of these automatically serve the same 'Application' over HTTP\/1,
    -- HTTP\/1.1, and HTTP\/2.
    run
  , runEnv
  , runSettings
  , runSettingsSocket
    -- * Settings
  , Settings
  , defaultSettings
    -- ** Setters
  , setPort
  , setHost
  , setOnException
  , setOnExceptionResponse
  , setOnOpen
  , setOnClose
  , setTimeout
  , setManager
  , setFdCacheDuration
  , setFileInfoCacheDuration
  , setBeforeMainLoop
  , setNoParsePath
  , setInstallShutdownHandler
  , setServerName
  , setMaximumBodyFlush
  , setFork
  , setAccept
  , setProxyProtocolNone
  , setProxyProtocolRequired
  , setProxyProtocolOptional
  , setSlowlorisSize
  , setHTTP2Disabled
  , setLogger
  , setServerPushLogger
  , setGracefulShutdownTimeout
  , setGracefulCloseTimeout1
  , setGracefulCloseTimeout2
  , setMaxTotalHeaderLength
  , setAltSvc
  , setMaxBuilderResponseBufferSize
    -- ** Getters
  , getPort
  , getHost
  , getOnOpen
  , getOnClose
  , getOnException
  , getGracefulShutdownTimeout
  , getGracefulCloseTimeout1
  , getGracefulCloseTimeout2
    -- ** Exception handler
  , defaultOnException
  , defaultShouldDisplayException
    -- ** Exception response handler
  , defaultOnExceptionResponse
  , exceptionResponseForDebug
    -- * Data types
  , HostPreference
  , Port
  , InvalidRequest (..)
    -- * Utilities
  , pauseTimeout
  , FileInfo(..)
  , getFileInfo
#ifdef MIN_VERSION_x509
  , clientCertificate
#endif
  , withApplication
  , withApplicationSettings
  , testWithApplication
  , testWithApplicationSettings
  , openFreePort
    -- * Version
  , warpVersion
    -- * HTTP/2
    -- ** HTTP2 data
  , HTTP2Data
  , http2dataPushPromise
  , http2dataTrailers
  , defaultHTTP2Data
  , getHTTP2Data
  , setHTTP2Data
  , modifyHTTP2Data
    -- ** Push promise
  , PushPromise
  , promisedPath
  , promisedFile
  , promisedResponseHeaders
  , promisedWeight
  , defaultPushPromise
  ) where

import UnliftIO.Exception (SomeException, throwIO)
import Data.Streaming.Network (HostPreference)
import qualified Data.Vault.Lazy as Vault
#ifdef MIN_VERSION_x509
import Data.X509
#endif
import qualified Network.HTTP.Types as H
import Network.Socket (Socket, SockAddr)
import Network.Wai (Request, Response, vault)
import System.TimeManager

import Network.Wai.Handler.Warp.FileInfoCache
import Network.Wai.Handler.Warp.HTTP2.Request (getHTTP2Data, setHTTP2Data, modifyHTTP2Data)
import Network.Wai.Handler.Warp.HTTP2.Types
import Network.Wai.Handler.Warp.Imports
import Network.Wai.Handler.Warp.Request
import Network.Wai.Handler.Warp.Response (warpVersion)
import Network.Wai.Handler.Warp.Run
import Network.Wai.Handler.Warp.Settings
import Network.Wai.Handler.Warp.Types hiding (getFileInfo)
import Network.Wai.Handler.Warp.WithApplication

-- | Port to listen on. Default value: 3000
--
-- Since 2.1.0
setPort :: Port -> Settings -> Settings
setPort :: Int -> Settings -> Settings
setPort Int
x Settings
y = Settings
y { settingsPort :: Int
settingsPort = Int
x }

-- | Interface to bind to. Default value: HostIPv4
--
-- Since 2.1.0
setHost :: HostPreference -> Settings -> Settings
setHost :: HostPreference -> Settings -> Settings
setHost HostPreference
x Settings
y = Settings
y { settingsHost :: HostPreference
settingsHost = HostPreference
x }

-- | What to do with exceptions thrown by either the application or server.
-- Default: 'defaultOnException'
--
-- Since 2.1.0
setOnException :: (Maybe Request -> SomeException -> IO ()) -> Settings -> Settings
setOnException :: (Maybe Request -> SomeException -> IO ()) -> Settings -> Settings
setOnException Maybe Request -> SomeException -> IO ()
x Settings
y = Settings
y { settingsOnException :: Maybe Request -> SomeException -> IO ()
settingsOnException = Maybe Request -> SomeException -> IO ()
x }

-- | A function to create a `Response` when an exception occurs.
-- Default: 'defaultOnExceptionResponse'
--
-- Note that an application can handle its own exceptions without interfering with Warp:
--
-- > myApp :: Application
-- > myApp request respond = innerApp `catch` onError
-- >   where
-- >     onError = respond . response500 request
-- >
-- > response500 :: Request -> SomeException -> Response
-- > response500 req someEx = responseLBS status500 -- ...
--
-- Since 2.1.0
setOnExceptionResponse :: (SomeException -> Response) -> Settings -> Settings
setOnExceptionResponse :: (SomeException -> Response) -> Settings -> Settings
setOnExceptionResponse SomeException -> Response
x Settings
y = Settings
y { settingsOnExceptionResponse :: SomeException -> Response
settingsOnExceptionResponse = SomeException -> Response
x }

-- | 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
setOnOpen :: (SockAddr -> IO Bool) -> Settings -> Settings
setOnOpen SockAddr -> IO Bool
x Settings
y = Settings
y { settingsOnOpen :: SockAddr -> IO Bool
settingsOnOpen = SockAddr -> IO Bool
x }

-- | What to do when a connection is closed. Default: do nothing.
--
-- Since 2.1.0
setOnClose :: (SockAddr -> IO ()) -> Settings -> Settings
setOnClose :: (SockAddr -> IO ()) -> Settings -> Settings
setOnClose SockAddr -> IO ()
x Settings
y = Settings
y { settingsOnClose :: SockAddr -> IO ()
settingsOnClose = SockAddr -> IO ()
x }

-- | "Slow-loris" timeout lower-bound value in seconds.  Connections where
-- network progress is made less frequently than this may be closed.  In
-- practice many connections may be allowed to go without progress for up to
-- twice this amount of time.  Note that this timeout is not applied to
-- application code, only network progress.
--
-- Default value: 30
--
-- Since 2.1.0
setTimeout :: Int -> Settings -> Settings
setTimeout :: Int -> Settings -> Settings
setTimeout Int
x Settings
y = Settings
y { settingsTimeout :: Int
settingsTimeout = Int
x }

-- | Use an existing timeout manager instead of spawning a new one. If used,
-- 'settingsTimeout' is ignored.
--
-- Since 2.1.0
setManager :: Manager -> Settings -> Settings
setManager :: Manager -> Settings -> Settings
setManager Manager
x Settings
y = Settings
y { settingsManager :: Maybe Manager
settingsManager = forall a. a -> Maybe a
Just Manager
x }

-- | 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: 0, was previously 10
--
-- Since 3.0.13
setFdCacheDuration :: Int -> Settings -> Settings
setFdCacheDuration :: Int -> Settings -> Settings
setFdCacheDuration Int
x Settings
y = Settings
y { settingsFdCacheDuration :: Int
settingsFdCacheDuration = Int
x }

-- | Cache duration time of file information in seconds. 0 means that the cache mechanism is not used.
--
-- The file information 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: 0
setFileInfoCacheDuration :: Int -> Settings -> Settings
setFileInfoCacheDuration :: Int -> Settings -> Settings
setFileInfoCacheDuration Int
x Settings
y = Settings
y { settingsFileInfoCacheDuration :: Int
settingsFileInfoCacheDuration = Int
x }

-- | 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
setBeforeMainLoop :: IO () -> Settings -> Settings
setBeforeMainLoop IO ()
x Settings
y = Settings
y { settingsBeforeMainLoop :: IO ()
settingsBeforeMainLoop = IO ()
x }

-- | Perform no parsing on the rawPathInfo.
--
-- This is useful for writing HTTP proxies.
--
-- Default: False
--
-- Since 2.1.0
setNoParsePath :: Bool -> Settings -> Settings
setNoParsePath :: Bool -> Settings -> Settings
setNoParsePath Bool
x Settings
y = Settings
y { settingsNoParsePath :: Bool
settingsNoParsePath = Bool
x }

-- | Get the listening port.
--
-- Since 2.1.1
getPort :: Settings -> Port
getPort :: Settings -> Int
getPort = Settings -> Int
settingsPort

-- | Get the interface to bind to.
--
-- Since 2.1.1
getHost :: Settings -> HostPreference
getHost :: Settings -> HostPreference
getHost = Settings -> HostPreference
settingsHost

-- | Get the action on opening connection.
getOnOpen :: Settings -> SockAddr -> IO Bool
getOnOpen :: Settings -> SockAddr -> IO Bool
getOnOpen = Settings -> SockAddr -> IO Bool
settingsOnOpen

-- | Get the action on closeing connection.
getOnClose :: Settings -> SockAddr -> IO ()
getOnClose :: Settings -> SockAddr -> IO ()
getOnClose = Settings -> SockAddr -> IO ()
settingsOnClose

-- | Get the exception handler.
getOnException :: Settings -> Maybe Request -> SomeException -> IO ()
getOnException :: Settings -> Maybe Request -> SomeException -> IO ()
getOnException = Settings -> Maybe Request -> SomeException -> IO ()
settingsOnException

-- | Get the graceful shutdown timeout
--
-- Since 3.2.8
getGracefulShutdownTimeout :: Settings -> Maybe Int
getGracefulShutdownTimeout :: Settings -> Maybe Int
getGracefulShutdownTimeout = Settings -> Maybe Int
settingsGracefulShutdownTimeout

-- | 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 closes the listen socket, at shutdown.
--
-- Example usage:
--
-- @
-- settings :: IO () -> 'Settings'
-- settings shutdownAction = 'setInstallShutdownHandler' shutdownHandler 'defaultSettings'
--   __where__
--     shutdownHandler closeSocket =
--       void $ 'System.Posix.Signals.installHandler' 'System.Posix.Signals.sigTERM' ('System.Posix.Signals.Catch' $ shutdownAction >> closeSocket) 'Nothing'
-- @
--
-- Note that by default, the graceful shutdown mode lasts indefinitely
-- (see 'setGracefulShutdownTimeout'). If you install a signal handler as above,
-- upon receiving that signal, the custom shutdown action will run /and/ all
-- outstanding requests will be handled.
--
-- You may instead prefer to do one or both of the following:
--
-- * Only wait a finite amount of time for outstanding requests to complete,
--   using 'setGracefulShutdownTimeout'.
-- * Only catch one signal, so the second hard-kills the Warp server, using
--   'System.Posix.Signals.CatchOnce'.
--
-- Default: does not install any code.
--
-- Since 3.0.1
setInstallShutdownHandler :: (IO () -> IO ()) -> Settings -> Settings
setInstallShutdownHandler :: (IO () -> IO ()) -> Settings -> Settings
setInstallShutdownHandler IO () -> IO ()
x Settings
y = Settings
y { settingsInstallShutdownHandler :: IO () -> IO ()
settingsInstallShutdownHandler = IO () -> IO ()
x }

-- | Default server name to be sent as the \"Server:\" header
--   if an application does not set one.
--   If an empty string is set, the \"Server:\" header is not sent.
--   This is true even if an application set one.
--
-- Since 3.0.2
setServerName :: ByteString -> Settings -> Settings
setServerName :: ByteString -> Settings -> Settings
setServerName ByteString
x Settings
y = Settings
y { settingsServerName :: ByteString
settingsServerName = ByteString
x }

-- | 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
setMaximumBodyFlush :: Maybe Int -> Settings -> Settings
setMaximumBodyFlush Maybe Int
x Settings
y
    | Just Int
x' <- Maybe Int
x, Int
x' forall a. Ord a => a -> a -> Bool
< Int
0 = forall a. HasCallStack => [Char] -> a
error [Char]
"setMaximumBodyFlush: must be positive"
    | Bool
otherwise = Settings
y { settingsMaximumBodyFlush :: Maybe Int
settingsMaximumBodyFlush = Maybe Int
x }

-- | 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
setFork :: (((forall a. IO a -> IO a) -> IO ()) -> IO ())
-> Settings -> Settings
setFork ((forall a. IO a -> IO a) -> IO ()) -> IO ()
fork' Settings
s = Settings
s { settingsFork :: ((forall a. IO a -> IO a) -> IO ()) -> IO ()
settingsFork = ((forall a. IO a -> IO a) -> IO ()) -> IO ()
fork' }

-- | 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
setAccept :: (Socket -> IO (Socket, SockAddr)) -> Settings -> Settings
setAccept :: (Socket -> IO (Socket, SockAddr)) -> Settings -> Settings
setAccept Socket -> IO (Socket, SockAddr)
accept' Settings
s = Settings
s { settingsAccept :: Socket -> IO (Socket, SockAddr)
settingsAccept = Socket -> IO (Socket, SockAddr)
accept' }

-- | Do not use the PROXY protocol.
--
-- Since 3.0.5
setProxyProtocolNone :: Settings -> Settings
setProxyProtocolNone :: Settings -> Settings
setProxyProtocolNone Settings
y = Settings
y { settingsProxyProtocol :: ProxyProtocol
settingsProxyProtocol = ProxyProtocol
ProxyProtocolNone }

-- | 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
setProxyProtocolRequired :: Settings -> Settings
setProxyProtocolRequired Settings
y = Settings
y { settingsProxyProtocol :: ProxyProtocol
settingsProxyProtocol = ProxyProtocol
ProxyProtocolRequired }

-- | 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 accessible
-- 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
setProxyProtocolOptional :: Settings -> Settings
setProxyProtocolOptional Settings
y = Settings
y { settingsProxyProtocol :: ProxyProtocol
settingsProxyProtocol = ProxyProtocol
ProxyProtocolOptional }

-- | Size in bytes read to prevent Slowloris attacks. Default value: 2048
--
-- Since 3.1.2
setSlowlorisSize :: Int -> Settings -> Settings
setSlowlorisSize :: Int -> Settings -> Settings
setSlowlorisSize Int
x Settings
y = Settings
y { settingsSlowlorisSize :: Int
settingsSlowlorisSize = Int
x }

-- | Disable HTTP2.
--
-- Since 3.1.7
setHTTP2Disabled :: Settings -> Settings
setHTTP2Disabled :: Settings -> Settings
setHTTP2Disabled Settings
y = Settings
y { settingsHTTP2Enabled :: Bool
settingsHTTP2Enabled = Bool
False }

-- | Setting a log function.
--
-- Since 3.X.X
setLogger :: (Request -> H.Status -> Maybe Integer -> IO ()) -- ^ request, status, maybe file-size
          -> Settings
          -> Settings
setLogger :: (Request -> Status -> Maybe Integer -> IO ())
-> Settings -> Settings
setLogger Request -> Status -> Maybe Integer -> IO ()
lgr Settings
y = Settings
y { settingsLogger :: Request -> Status -> Maybe Integer -> IO ()
settingsLogger = Request -> Status -> Maybe Integer -> IO ()
lgr }

-- | Setting a log function for HTTP/2 server push.
--
--   Since: 3.2.7
setServerPushLogger :: (Request -> ByteString -> Integer -> IO ()) -- ^ request, path, file-size
                    -> Settings
                    -> Settings
setServerPushLogger :: (Request -> ByteString -> Integer -> IO ()) -> Settings -> Settings
setServerPushLogger Request -> ByteString -> Integer -> IO ()
lgr Settings
y = Settings
y { settingsServerPushLogger :: Request -> ByteString -> Integer -> IO ()
settingsServerPushLogger = Request -> ByteString -> Integer -> IO ()
lgr }

-- | Set the graceful shutdown timeout. A timeout of `Nothing' will
-- wait indefinitely, and a number, if provided, will be treated as seconds
-- to wait for requests to finish, before shutting down the server entirely.
--
-- Graceful shutdown mode is entered when the server socket is closed; see
-- 'setInstallShutdownHandler' for an example of how this could be done in
-- response to a UNIX signal.
--
-- Since 3.2.8
setGracefulShutdownTimeout :: Maybe Int
                           -> Settings -> Settings
setGracefulShutdownTimeout :: Maybe Int -> Settings -> Settings
setGracefulShutdownTimeout Maybe Int
time Settings
y = Settings
y { settingsGracefulShutdownTimeout :: Maybe Int
settingsGracefulShutdownTimeout = Maybe Int
time }

-- | Set the maximum header size that Warp will tolerate when using HTTP/1.x.
--
-- Since 3.3.8
setMaxTotalHeaderLength :: Int -> Settings -> Settings
setMaxTotalHeaderLength :: Int -> Settings -> Settings
setMaxTotalHeaderLength Int
maxTotalHeaderLength Settings
settings = Settings
settings
  { settingsMaxTotalHeaderLength :: Int
settingsMaxTotalHeaderLength = Int
maxTotalHeaderLength }


-- | Setting the header value of Alternative Services (AltSvc:).
--
-- Since 3.3.11
setAltSvc :: ByteString -> Settings -> Settings
setAltSvc :: ByteString -> Settings -> Settings
setAltSvc ByteString
altsvc Settings
settings = Settings
settings { settingsAltSvc :: Maybe ByteString
settingsAltSvc = forall a. a -> Maybe a
Just ByteString
altsvc }

-- | Set the maximum buffer size for sending `Builder` responses.
--
-- Since 3.3.22
setMaxBuilderResponseBufferSize :: Int -> Settings -> Settings
setMaxBuilderResponseBufferSize :: Int -> Settings -> Settings
setMaxBuilderResponseBufferSize Int
maxRspBufSize Settings
settings = Settings
settings { settingsMaxBuilderResponseBufferSize :: Int
settingsMaxBuilderResponseBufferSize = Int
maxRspBufSize }

-- | 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 ()
pauseTimeout :: Request -> IO ()
pauseTimeout = forall a. a -> Maybe a -> a
fromMaybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Key a -> Vault -> Maybe a
Vault.lookup Key (IO ())
pauseTimeoutKey forall b c a. (b -> c) -> (a -> b) -> a -> c
. Request -> Vault
vault

-- | Getting file information of the target file.
--
--   This function first uses a stat(2) or similar system call
--   to obtain information of the target file, then registers
--   it into the internal cache.
--   From the next time, the information is obtained
--   from the cache. This reduces the overhead to call the system call.
--   The internal cache is refreshed every duration specified by
--   'setFileInfoCacheDuration'.
--
--   This function throws an 'IO' exception if the information is not
--   available. For instance, the target file does not exist.
--   If this function is used an a Request generated by a WAI
--   backend besides Warp, it also throws an 'IO' exception.
--
-- Since 3.1.10
getFileInfo :: Request -> FilePath -> IO FileInfo
getFileInfo :: Request -> [Char] -> IO FileInfo
getFileInfo = forall a. a -> Maybe a -> a
fromMaybe (\[Char]
_ -> forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO ([Char] -> IOError
userError [Char]
"getFileInfo")) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Key a -> Vault -> Maybe a
Vault.lookup Key ([Char] -> IO FileInfo)
getFileInfoKey forall b c a. (b -> c) -> (a -> b) -> a -> c
. Request -> Vault
vault

-- | 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
setGracefulCloseTimeout1 :: Int -> Settings -> Settings
setGracefulCloseTimeout1 :: Int -> Settings -> Settings
setGracefulCloseTimeout1 Int
x Settings
y = Settings
y { settingsGracefulCloseTimeout1 :: Int
settingsGracefulCloseTimeout1 = Int
x }

-- | A timeout to limit the time (in milliseconds) waiting for
--   FIN for HTTP/1.x. 0 means uses immediate close.
--
-- Since 3.3.5
getGracefulCloseTimeout1 :: Settings -> Int
getGracefulCloseTimeout1 :: Settings -> Int
getGracefulCloseTimeout1 = Settings -> Int
settingsGracefulCloseTimeout1

-- | 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
setGracefulCloseTimeout2 :: Int -> Settings -> Settings
setGracefulCloseTimeout2 :: Int -> Settings -> Settings
setGracefulCloseTimeout2 Int
x Settings
y = Settings
y { settingsGracefulCloseTimeout2 :: Int
settingsGracefulCloseTimeout2 = Int
x }

-- | A timeout to limit the time (in milliseconds) waiting for
--   FIN for HTTP/2. 0 means uses immediate close.
--
-- Since 3.3.5
getGracefulCloseTimeout2 :: Settings -> Int
getGracefulCloseTimeout2 :: Settings -> Int
getGracefulCloseTimeout2 = Settings -> Int
settingsGracefulCloseTimeout2

#ifdef MIN_VERSION_x509
-- | Getting information of client certificate.
--
-- Since 3.3.5
clientCertificate :: Request -> Maybe CertificateChain
clientCertificate :: Request -> Maybe CertificateChain
clientCertificate = forall (m :: * -> *) a. Monad m => m (m a) -> m a
join forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Key a -> Vault -> Maybe a
Vault.lookup Key (Maybe CertificateChain)
getClientCertificateKey forall b c a. (b -> c) -> (a -> b) -> a -> c
. Request -> Vault
vault
#endif