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]
- queryString :: Request -> Query
- requestHeader :: HeaderName -> Request -> Maybe ByteString
- requestHeaders :: Request -> RequestHeaders
- requestBodyLength :: Request -> RequestBodyLength
- getRequestBodyChunk :: Request -> IO ByteString
- data Response a = Response {}
- responseHeader :: HeaderName -> Response a -> Maybe ByteString
- setResponseHeader :: HeaderName -> ByteString -> Response a -> Response a
- waiResponse :: Response ByteString -> Response
- respond :: Status -> Maybe a -> Response a
- continue100 :: Response a
- switchingProtocols101 :: Response a
- ok200 :: a -> Response a
- created201 :: a -> Response a
- accepted202 :: a -> Response a
- nonAuthoritative203 :: a -> Response a
- noContent204 :: Response a
- resetContent205 :: Response a
- partialContent206 :: a -> Response a
- multipleChoices300 :: a -> Response a
- movedPermanently301 :: a -> Response a
- found302 :: a -> Response a
- seeOther303 :: a -> Response a
- notModified304 :: Response a
- temporaryRedirect307 :: a -> Response a
- permanentRedirect308 :: a -> Response a
- badRequest400 :: a -> Response a
- unauthorized401 :: a -> Response a
- paymentRequired402 :: a -> Response a
- forbidden403 :: a -> Response a
- notFound404 :: Response a
- methodNotAllowed405 :: a -> Response a
- notAcceptable406 :: a -> Response a
- proxyAuthenticationRequired407 :: a -> Response a
- requestTimeout408 :: a -> Response a
- conflict409 :: a -> Response a
- gone410 :: a -> Response a
- lengthRequired411 :: a -> Response a
- preconditionFailed412 :: a -> Response a
- requestEntityTooLarge413 :: a -> Response a
- requestURITooLong414 :: a -> Response a
- unsupportedMediaType415 :: a -> Response a
- requestedRangeNotSatisfiable416 :: a -> Response a
- expectationFailed417 :: a -> Response a
- imATeapot418 :: a -> Response a
- unprocessableEntity422 :: a -> Response a
- preconditionRequired428 :: a -> Response a
- tooManyRequests429 :: a -> Response a
- requestHeaderFieldsTooLarge431 :: a -> Response a
- internalServerError500 :: a -> Response a
- notImplemented501 :: a -> Response a
- badGateway502 :: a -> Response a
- serviceUnavailable503 :: a -> Response a
- gatewayTimeout504 :: a -> Response a
- httpVersionNotSupported505 :: a -> Response a
- networkAuthenticationRequired511 :: a -> Response a
- type Handler' m req a = Kleisli m (Linked req Request) (Response a)
- type Handler req a = Handler' Router req a
- type Middleware' m req req' a' a = Handler' m req' a' -> Handler' m req a
- type Middleware req req' a' a = Middleware' Router req req' a' a
- type RequestMiddleware' m req req' a = Middleware' m req req' a a
- type RequestMiddleware req req' a = RequestMiddleware' Router req req' a
- type ResponseMiddleware' m req a' a = Middleware' m req req a' a
- type ResponseMiddleware req a' a = ResponseMiddleware' Router req a' a
- newtype Router a = Router {}
- class (MonadState PathInfo m, Alternative m, MonadPlus m) => MonadRouter m where
- rejectRoute :: m a
- errorResponse :: Response ByteString -> m a
- catchErrorResponse :: m a -> (Response ByteString -> m a) -> m a
- newtype PathInfo = PathInfo [Text]
- data RouteError
- transform :: (forall x. m x -> n x) -> Handler' m req a -> Handler' n req a
- runRoute :: ToByteString a => Handler '[] a -> Request -> IO Response
- toApplication :: ToByteString a => Handler '[] a -> Application
WebGear Request
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.
requestHeader :: HeaderName -> Request -> Maybe ByteString Source #
Get the value of a request header
requestHeaders :: Request -> RequestHeaders #
A list of headers (a pair of key and value) in an HTTP request.
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
An HTTP response sent from the server to the client.
The response contains a status, optional headers and an optional
body of type a
.
Response | |
|
Instances
responseHeader :: HeaderName -> Response a -> Maybe ByteString Source #
Looks up a response header
setResponseHeader :: HeaderName -> ByteString -> Response a -> Response a Source #
Set a response header value
waiResponse :: Response ByteString -> Response Source #
Convert a WebGear response to a WAI Response.
Creating responses
continue100 :: Response a Source #
Continue 100 response
switchingProtocols101 :: Response a Source #
Switching Protocols 101 response
created201 :: a -> Response a Source #
Created 201 response
accepted202 :: a -> Response a Source #
Accepted 202 response
nonAuthoritative203 :: a -> Response a Source #
Non-Authoritative 203 response
noContent204 :: Response a Source #
No Content 204 response
resetContent205 :: Response a Source #
Reset Content 205 response
partialContent206 :: a -> Response a Source #
Partial Content 206 response
multipleChoices300 :: a -> Response a Source #
Multiple Choices 300 response
movedPermanently301 :: a -> Response a Source #
Moved Permanently 301 response
seeOther303 :: a -> Response a Source #
See Other 303 response
notModified304 :: Response a Source #
Not Modified 304 response
temporaryRedirect307 :: a -> Response a Source #
Temporary Redirect 307 response
permanentRedirect308 :: a -> Response a Source #
Permanent Redirect 308 response
badRequest400 :: a -> Response a Source #
Bad Request 400 response
unauthorized401 :: a -> Response a Source #
Unauthorized 401 response
paymentRequired402 :: a -> Response a Source #
Payment Required 402 response
forbidden403 :: a -> Response a Source #
Forbidden 403 response
notFound404 :: Response a Source #
Not Found 404 response
methodNotAllowed405 :: a -> Response a Source #
Method Not Allowed 405 response
notAcceptable406 :: a -> Response a Source #
Not Acceptable 406 response
proxyAuthenticationRequired407 :: a -> Response a Source #
Proxy Authentication Required 407 response
requestTimeout408 :: a -> Response a Source #
Request Timeout 408 response
conflict409 :: a -> Response a Source #
Conflict 409 response
lengthRequired411 :: a -> Response a Source #
Length Required 411 response
preconditionFailed412 :: a -> Response a Source #
Precondition Failed 412 response
requestEntityTooLarge413 :: a -> Response a Source #
Request Entity Too Large 413 response
requestURITooLong414 :: a -> Response a Source #
Request URI Too Long 414 response
unsupportedMediaType415 :: a -> Response a Source #
Unsupported Media Type 415 response
requestedRangeNotSatisfiable416 :: a -> Response a Source #
Requested Range Not Satisfiable 416 response
expectationFailed417 :: a -> Response a Source #
Expectation Failed 417 response
imATeapot418 :: a -> Response a Source #
I'm A Teapot 418 response
unprocessableEntity422 :: a -> Response a Source #
Unprocessable Entity 422 response
preconditionRequired428 :: a -> Response a Source #
Precondition Required 428 response
tooManyRequests429 :: a -> Response a Source #
Too Many Requests 429 response
requestHeaderFieldsTooLarge431 :: a -> Response a Source #
Request Header Fields Too Large 431 response
internalServerError500 :: a -> Response a Source #
Internal Server Error 500 response
notImplemented501 :: a -> Response a Source #
Not Implemented 501 response
badGateway502 :: a -> Response a Source #
Bad Gateway 502 response
serviceUnavailable503 :: a -> Response a Source #
Service Unavailable 503 response
gatewayTimeout504 :: a -> Response a Source #
Gateway Timeout 504 response
httpVersionNotSupported505 :: a -> Response a Source #
HTTP Version Not Supported 505 response
networkAuthenticationRequired511 :: a -> Response a Source #
Network Authentication Required 511 response
type Handler' m req a = Kleisli m (Linked req Request) (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.
type Middleware' m req req' a' a = Handler' m req' a' -> Handler' m req 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.
- Use the linked value of any of the request traits.
- Change the response body.
type Middleware req req' a' a = Middleware' Router req req' a' a Source #
A middleware that runs on the Router
monad.
type RequestMiddleware' m req req' a = Middleware' m req req' a a Source #
A middleware that manipulates only the request traits and passes the response through.
type RequestMiddleware req req' a = RequestMiddleware' Router req req' a Source #
A request middleware that runs on the Router
monad.
type ResponseMiddleware' m req a' a = Middleware' m req req a' a Source #
A middleware that manipulates only the response and passes the request through.
type ResponseMiddleware req a' a = ResponseMiddleware' Router req a' a Source #
A response middleware that runs on the Router
monad.
The monad for routing.
Instances
Monad Router Source # | |
Functor Router Source # | |
Applicative Router Source # | |
Alternative Router Source # | |
MonadPlus Router Source # | |
MonadIO Router Source # | |
Defined in WebGear.Types | |
MonadRouter Router Source # | |
Defined in WebGear.Types rejectRoute :: Router a Source # errorResponse :: Response ByteString -> Router a Source # catchErrorResponse :: Router a -> (Response ByteString -> Router a) -> Router a Source # | |
MonadState PathInfo Router Source # | |
MonadError RouteError Router Source # | |
Defined in WebGear.Types throwError :: RouteError -> Router a # catchError :: Router a -> (RouteError -> Router a) -> Router a # |
class (MonadState PathInfo m, Alternative m, MonadPlus m) => MonadRouter m where Source #
HTTP request routing with short circuiting behavior.
rejectRoute :: m a Source #
Mark the current route as rejected, alternatives can be tried
errorResponse :: Response ByteString -> m a Source #
Short-circuit the current handler and return a response
catchErrorResponse :: m a -> (Response ByteString -> m a) -> m a Source #
Handle an error response
Instances
MonadRouter Router Source # | |
Defined in WebGear.Types rejectRoute :: Router a Source # errorResponse :: Response ByteString -> Router a Source # catchErrorResponse :: Router a -> (Response ByteString -> Router a) -> Router a Source # |
The path components to be matched by routing machinery
data RouteError Source #
Responses that cause routes to abort execution
RouteMismatch | A route did not match and the next one can be tried |
ErrorResponse (Response ByteString) | A route matched but returned a short circuiting error response |
Instances
transform :: (forall x. m x -> n x) -> Handler' m req a -> Handler' n req a Source #
A natural transformation of handler monads.
This is useful if you want to run a handler in a monad other than
Router
.
runRoute :: ToByteString a => Handler '[] a -> Request -> IO Response Source #
Convert a routable handler into a plain function from request to response.
toApplication :: ToByteString a => Handler '[] a -> Application Source #
Convert a routable handler into a Wai application