h&42<      !"#$%&'()*+,-./0123456789:; Safe-Inferred%&waiA special datatype to indicate that the WAI handler has received the response. This is to avoid the need for Rank2Types in the definition of Application.It is highly advised that only WAI handlers import and use the data constructor for this data type.waiInformation on which part to be sent. Sophisticated application handles Range (and If-Range) then create .waiThe size of the request body. In the case of chunked bodies, the size will not be known. waiRepresents a streaming HTTP response body. It's a function of two parameters; the first parameter provides a means of sending another chunk of data, and the second parameter provides a means of flushing the data to the client.waiInformation on the request sent by the client. This abstracts away the details of the underlying implementation.waiRequest method such as GET.waiHTTP version such as 1.1.waiExtra path information sent by the client. The meaning varies slightly depending on backend; in a standalone server setting, this is most likely all information after the domain name. In a CGI application, this would be the information following the path to the CGI executable itself.Middlewares and routing tools should not modify this raw value, as it may be used for such things as creating redirect destinations by applications. Instead, if you are writing a middleware or routing framework, modify the pathInfo instead. This is the approach taken by systems like Yesod subsites.Note: At the time of writing this documentation, there is at least one system (Network.Wai.UrlMap from  wai-extra) that does not follow the above recommendation. Therefore, it is recommended that you test the behavior of your application when using  rawPathInfo0 and any form of library that might modify the Request.waiIf no query string was specified, this should be empty. This value will include the leading question mark. Do not modify this raw value - modify queryString instead.wai?A list of headers (a pair of key and value) in an HTTP request.wai-Was this request made over an SSL connection?Note that this value will not tell you if the client originally made this request over SSL, but rather whether the current connection is SSL. The distinction lies with reverse proxies. In many cases, the client will connect to a load balancer over SSL, but connect to the WAI handler without SSL. In such a case,  will be <=, but from a user perspective, there is a secure connection.waiThe client's host information.waiPath info in individual pieces - the URL without a hostname/port and without a query string, split on forward slashes.wai Parsed query string information.wai(Get the next chunk of the body. Returns = when the body is fully consumed. Since 3.2.2, this is deprecated in favor of ".waiA location for arbitrary data to be shared by applications and middleware.waiThe size of the request body. In the case of a chunked request body, this may be unknown.wai/The value of the Host header in a HTTP request.wai0The value of the Range header in a HTTP request. wai2The value of the Referer header in a HTTP request.!wai5The value of the User-Agent header in a HTTP request."wai(Get the next chunk of the body. Returns =" when the body is fully consumed.#waiSet the  attribute on a request without triggering a deprecation warning.The supplied IO action should return the next chunk of the body each time it is called and =! when it has been fully consumed.$   ! "#$! "#    Safe-Inferred2V'waiA  Middleware= is a component that sits between the server and application.It can modify both the  and  , to provide simple transformations that are required for all (or most of) your web server@s routes.Users of middleware'If you are trying to apply one or more ' s to your (, just call them as functions.For example, if you have corsMiddleware and authorizationMiddleware/, and you want to authorize first, you can do: let allMiddleware app = authorizationMiddleware (corsMiddleware app)  to get a new ', which first authorizes, then sets, CORS headers. The @outer@ middleware is called first.You can also chain them via >: let allMiddleware = authorizationMiddleware . corsMiddleware . @ more middleware here @ Then, once you have an app :: Application&, you can wrap it in your middleware: -let myApp = allMiddleware app :: Application and run it as usual: Warp.run port myApp Authors of middlewareWhen fully expanded, ' has the type signature: (Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived) -> Request -> (Response -> IO ResponseReceived) -> IO ResponseReceivedor if we shorten to .type Respond = Response -> IO ResponseReceived: (Request -> Respond -> IO ResponseReceived) -> Request -> Respond -> IO ResponseReceivedso a middleware definition takes 3 arguments, an inner application, a request and a response callback."Compare with the type of a simple (: )Request -> Respond -> IO ResponseReceived It takes the  and Respond , but not the extra application.9Said differently, a middleware has the power of a normal ( @ it can inspect the  and return a  % @ but it can (and in many cases it should) also call the ( which was passed to it.Modifying the A lot of middleware just looks at the request and does something based on its values.For example, the authorizationMiddleware from above could look at the  Authorization HTTP header and run  https://jwt.io/JWT) verification logic against the database. ?authorizationMiddleware app req respond = do case verifyJWT ( req) of InvalidJWT err -> respond (invalidJWTResponse err) ValidJWT -> app req respond Notice how the inner app is called when the validation was successful. If it was not, we can respond e.g. with  Application -> Request -> Respond -> IO ResponseReceived authorizationMiddleware jwtSettings req respond = case verifyJWT jwtSettings ( req) of InvalidJWT err -> respond (invalidJWTResponse err) ValidJWT -> app req respond or alternatively: 5authorizationMiddleware :: JWTSettings -> Middleware 'Perhaps less intuitively, you can also pass on% data from middleware to the wrapped (: authorizationMiddleware :: JWTSettings -> (JWT -> Application) -> Request -> Respond -> IO ResponseReceived authorizationMiddleware jwtSettings req respond = case verifyJWT jwtSettings ( req) of InvalidJWT err -> respond (invalidJWTResponse err) ValidJWT jwt -> app jwt req respond although then, chaining different middleware has to take this extra argument into account: let finalApp = authorizationMiddleware (\jwt -> corsMiddleware (@ more middleware here @ (app jwt))) Modifying the  ' can also modify the  + that is returned by the inner application.This is done by taking the respond$ callback, using it to define a new respond', and passing this new respond' to the app: gzipMiddleware app req respond = do let respond' resp = do resp' <- gzipResponseBody resp respond resp' app req respond' However, modifying the response (especially the response body) is not trivial, so in order to get a sense of how to do it (dealing with the type of 01), it@s best to look at an example, for example  https://hackage.haskell.org/package/wai-extra/docs/src/Network.Wai.Middleware.Gzip.html#gzip the GZIP middleware of wai-extra.(waiThe WAI application.Note that, since WAI 3.0, this type is structured in continuation passing style to allow for proper safe resource handling. This was handled in the past via other means (e.g.,  ResourceT). As a demonstration: app :: Application app req respond = bracket_ (putStrLn "Allocating scarce resource") (putStrLn "Cleaning up") (respond $ responseLBS status200 [] "Hello World") )wai Creating   from a file.*wai Creating   from ?..Some questions and answers about the usage of ? here:Q1. Shouldn't it be at the user's discretion to use Builders internally and then create a stream of ByteStrings?A1. That would be less efficient, as we wouldn't get cheap concatenation with the response headers.Q2. Isn't it really inefficient to convert from ByteString to Builder, and then right back to ByteString?A2. No. If the ByteStrings are small, then they will be copied into a larger buffer, which should be a performance gain overall (less system calls). If they are already large, then an insert operation is used to avoid copying.Q3. Doesn't this prevent us from creating comet-style servers, since data will be cached?A3. You can force a Builder to output a ByteString before it is an optimal size by sending a flush command.+wai Creating   from @. This is a wrapper for *.,wai Creating   from a stream of values.In order to allocate resources in an exception-safe manner, you can use the bracket pattern outside of the call to responseStream. As a trivial example: app :: Application app req respond = bracket_ (putStrLn "Allocating scarce resource") (putStrLn "Cleaning up") $ respond $ responseStream status200 [] $ \write flush -> do write $ byteString "Hello\n" flush write $ byteString "World\n" $Note that in some cases you can use bracket from inside responseStream as well. However, placing the call on the outside allows your status value and response headers to depend on the scarce resource.-waiCreate a response for a raw application. This is useful for "upgrade" situations such as WebSockets, where an application requests for the server to grant it raw network access.This function requires a backup response to be provided, for the case where the handler in question does not support such upgrading (e.g., CGI apps).In the event that you read from the request body before returning a  responseRaw, behavior is undefined..wai Accessing A in  ./wai Accessing B in  .0wai#Converting the body information in   to a  .1waiApply the provided function to the response header list of the Response.2waiApply the provided function to the response status of the Response.3waiA default, blank request.4wai.Apply a function that modifies a request as a '5wai/Apply a function that modifies a response as a '6waiConditionally apply a '7wai7Get the request body as a lazy ByteString. However, do not use any lazy I/O, instead reading the entire body into memory strictly.Note: Since this function consumes the request body, future calls to it will return the empty string.8wai Synonym for 7. This function name is meant to signal the non-idempotent nature of 7.9waiGet the request body as a lazy ByteString. This uses lazy I/O under the surface, and therefore all typical warnings regarding lazy I/O apply.Note: Since this function consumes the request body, future calls to it will return the empty string.:wai Synonym for 9. This function name is meant to signal the non-idempotent nature of 9.;wai>Apply the provided function to the request header list of the .3 ! "#'()*+,-./0123456789:;3('3 " !789:#; )*+,-./012645      !"#$%&'()*+,-./0123456789:;<=>?@ABCD?EF?GHIJKILM wai-3.2.4-505yavFEWpQJTWXjRRik8n Network.WaiNetwork.Wai.InternalResponseReceivedFilePartfilePartOffsetfilePartByteCountfilePartFileSizeRequestBodyLength ChunkedBody KnownLength StreamingBodyResponse ResponseFileResponseBuilderResponseStream ResponseRawRequest requestMethod httpVersion rawPathInforawQueryStringrequestHeadersisSecure remoteHostpathInfo queryString requestBodyvaultrequestBodyLengthrequestHeaderHostrequestHeaderRangerequestHeaderRefererrequestHeaderUserAgentgetRequestBodyChunksetRequestBodyChunks $fShowRequest$fShowFilePart$fShowRequestBodyLength Middleware Application responseFileresponseBuilder responseLBSresponseStream responseRawresponseStatusresponseHeadersresponseToStreammapResponseHeadersmapResponseStatusdefaultRequest modifyRequestmodifyResponse ifRequeststrictRequestBodyconsumeRequestBodyStrictlazyRequestBodyconsumeRequestBodyLazymapRequestHeadersghc-prim GHC.TypesFalsebytestring-0.11.3.1Data.ByteString.InternalemptybaseGHC.Base. Data.ByteString.Builder.InternalBuilderData.ByteString.Lazy.Internal ByteString(http-types-0.12.4-8sVzaiF2LjrERDtipkARMDNetwork.HTTP.Types.StatusStatusNetwork.HTTP.Types.HeaderResponseHeaders