Copyright | (c) Raghu Kaippully 2020 |
---|---|
License | MPL-2.0 |
Maintainer | rkaippully@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
Common types and functions used throughout WebGear.
Synopsis
- data Request
- remoteHost :: Request -> SockAddr
- httpVersion :: Request -> HttpVersion
- isSecure :: Request -> Bool
- requestMethod :: Request -> Method
- pathInfo :: Request -> [Text]
- setPathInfo :: [Text] -> Request -> Request
- queryString :: Request -> Query
- requestHeaders :: Request -> RequestHeaders
- requestHeader :: HeaderName -> Request -> Maybe ByteString
- requestBodyLength :: Request -> RequestBodyLength
- getRequestBodyChunk :: Request -> IO ByteString
- data Response a = Response {}
- waiResponse :: Response ByteString -> Response
- addResponseHeader :: Header -> Response a -> Response a
- type Handler m req res a = Kleisli m (Linked req Request) (Linked res (Response a))
- type Middleware m req req' res' res a' a = Handler m req' res' a' -> Handler m req res a
- type RequestMiddleware m req req' res a = Middleware m req req' res res a a
- type ResponseMiddleware m req res' res a = Middleware m req req res' res a a
WebGear Request
WebGear requests are WAI requests. This module reexports a number of useful functions that operate on requests from Network.Wai module.
Information on the request sent by the client. This abstracts away the details of the underlying implementation.
Instances
remoteHost :: Request -> SockAddr #
The client's host information.
httpVersion :: Request -> HttpVersion #
HTTP version such as 1.1.
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, isSecure
will be False
, but from a user
perspective, there is a secure connection.
requestMethod :: Request -> Method #
Request method such as GET.
pathInfo :: Request -> [Text] #
Path info in individual pieces - the URL without a hostname/port and without a query string, split on forward slashes.
queryString :: Request -> Query #
Parsed query string information.
requestHeaders :: Request -> RequestHeaders #
A list of headers (a pair of key and value) in an HTTP request.
requestHeader :: HeaderName -> Request -> Maybe ByteString Source #
Get the value of a request header
requestBodyLength :: Request -> RequestBodyLength #
The size of the request body. In the case of a chunked request body, this may be unknown.
Since 1.4.0
getRequestBodyChunk :: Request -> IO ByteString #
Get the next chunk of the body. Returns empty
when the
body is fully consumed.
Since: wai-3.2.2
WebGear Response
A response sent from the server to the client.
The response contains a status, optional headers and an optional
body of type a
.
Response | |
|
Instances
Monad m => MonadRouter (RouterT m) Source # | |
Defined in WebGear.Route rejectRoute :: RouterT m a Source # failHandler :: Response ByteString -> RouterT m a Source # |
waiResponse :: Response ByteString -> Response Source #
Convert a WebGear response to a WAI Response.
type Handler m req res a = Kleisli m (Linked req Request) (Linked res (Response a)) Source #
A handler is a function from a request to response in a monadic context. Both the request and the response can have linked traits.
The type level list req
contains all the traits expected to be
present in the request. The handler will produce a response that
satisfies all the traits in the type level list res
.
type Middleware m req req' res' res a' a = Handler m req' res' a' -> Handler m req res a Source #
A middleware takes a handler as input and produces another handler that usually adds some functionality.
A middleware can do a number of things with the request handling such as:
- Change the request traits before invoking the handler.
- Change the response traits before passing it back to its caller.
- Use the linked value of any of the request or response traits.
- Change the response body.
type RequestMiddleware m req req' res a = Middleware m req req' res res a a Source #
A middleware that manipulates only the request traits and leaves the response unchanged.
type ResponseMiddleware m req res' res a = Middleware m req req res' res a a Source #
A middleware that manipulates only the response traits and leaves the request unchanged.