Safe Haskell | None |
---|---|
Language | Haskell98 |
- data Resource m = Resource {
- serviceAvailable :: HaltT m Bool
- uriTooLong :: HaltT m Bool
- allowedMethods :: m [Method]
- malformedRequest :: HaltT m Bool
- isAuthorized :: HaltT m Authorized
- forbidden :: HaltT m Bool
- validContentHeaders :: HaltT m Bool
- knownContentType :: HaltT m Bool
- validEntityLength :: HaltT m Bool
- options :: m ResponseHeaders
- contentTypesProvided :: m [(MediaType, HaltT m Body)]
- charsetsProvided :: m CharsetsProvided
- encodingsProvided :: m [(Encoding, Body -> Body)]
- resourceExists :: HaltT m Bool
- generateETag :: MaybeT m ETag
- lastModified :: MaybeT m HTTPDate
- expires :: MaybeT m HTTPDate
- movedPermanently :: MaybeT (HaltT m) ByteString
- movedTemporarily :: MaybeT (HaltT m) ByteString
- previouslyExisted :: HaltT m Bool
- allowMissingPost :: HaltT m Bool
- deleteResource :: HaltT m Bool
- deleteCompleted :: HaltT m Bool
- postAction :: m (PostAction m)
- contentTypesAccepted :: m [(MediaType, HaltT m ())]
- variances :: m [HeaderName]
- multipleChoices :: HaltT m Bool
- isConflict :: m Bool
- finishRequest :: m ()
- resource :: Monad m => Resource m
- resourceWithBody :: Monad m => MediaType -> m Body -> Resource m
- resourceWithHtml :: Monad m => m Body -> Resource m
- type Encoding = CI ByteString
- data Authorized
- data ETag
- data PostAction m
- = PostCreate [Text]
- | PostCreateRedir [Text]
- | PostProcess (HaltT m ())
- | PostProcessRedir (HaltT m ByteString)
- postCreate :: Monad m => [Text] -> m (PostAction m)
- postCreateRedir :: Monad m => [Text] -> m (PostAction m)
- postProcess :: Monad m => HaltT m () -> m (PostAction m)
- postProcessRedir :: Monad m => HaltT m ByteString -> m (PostAction m)
- data HaltT m a
- halt :: Monad m => Status -> HaltT m a
- werror :: Monad m => ByteString -> HaltT m a
- werrorWith :: Monad m => Status -> ByteString -> HaltT m a
- getDispatchPath :: (MonadState s m, HasReqData s) => m [Text]
- data ReqData
- class HasReqData c
- type Charset = CI ByteString
- data CharsetsProvided
- provideCharsets :: Monad m => NonEmpty (Charset, Body -> Body) -> m CharsetsProvided
- type HeadersMap = HashMap HeaderName [ByteString]
- addResponseHeader :: (MonadState s m, HasReqData s) => HeaderName -> ByteString -> m ()
- putResponseHeader :: (MonadState s m, HasReqData s) => HeaderName -> ByteString -> m ()
- type Body = ByteString
- lazyByteStringBody :: ByteString -> Body
- byteStringBody :: ByteString -> Body
- lazyTextBody :: Text -> Body
- textBody :: Text -> Body
- strBody :: String -> Body
- writeBody :: (MonadState s m, HasReqData s) => ByteString -> m ()
- writeLBS :: (MonadState s m, HasReqData s) => ByteString -> m ()
- writeBS :: (MonadState s m, HasReqData s) => ByteString -> m ()
- writeLT :: (MonadState s m, HasReqData s) => Text -> m ()
- writeText :: (MonadState s m, HasReqData s) => Text -> m ()
- writeStr :: (MonadState s m, HasReqData s) => String -> m ()
- module Network.HTTP.Date
- module Network.HTTP.Media
- module Network.HTTP.Types
- hAcceptCharset :: HeaderName
- hAcceptEncoding :: HeaderName
- hAllow :: HeaderName
- hETag :: HeaderName
- hExpires :: HeaderName
- hIfMatch :: HeaderName
- hIfNoneMatch :: HeaderName
- hIfUnmodifiedSince :: HeaderName
- hTransferEncoding :: HeaderName
- hVary :: HeaderName
- hWWWAuthenticate :: HeaderName
Resources
A Resource
is a dictionary of functions which are used in the Webcrank
decision process to determine how requests should be handled.
Each function has a type of either m a
or
.
A resource function which yields a HaltT
m aHaltT m a
value allows the function
to terminate the request processing early using
or
halt
.werror
The defaults documented are used by the
smart constructor.
A resource that responds to resource
GET
requests with an HTML response would be
written as
myResource = resource { contentTypesProvided = return $ [("text/html", return "Hello world!")] }
and responseWithBody
are additional
smart constructors useful creating resources.responseWithHtml
Resource | |
|
resource :: Monad m => Resource m Source
Builds a Resource m
value where all the resource functions will
return default values as described in the
function
documentation.Resource
resourceWithBody :: Monad m => MediaType -> m Body -> Resource m Source
Creates a resource that provides a single content type.
resourceWithHtml :: Monad m => m Body -> Resource m Source
Creates a resource that provides a text/html
content type.
type Encoding = CI ByteString Source
Content coding type, e.g. gzip, decompress. See
.encodingsProvided
data Authorized Source
Indicates whether client is authorized to perform the requested
operation on the resource. See
.isAuthorized
Authorized | Tells Webcrank that the client is authorized to perform the requested operation on the resource. |
Unauthorized ByteString | Tells Webcrank that the client is not authorized to perform
the operation on the resource. The value is sent in the
|
Weak or strong entity tags as used in HTTP ETag and If-*-Match
headers.
data PostAction m Source
How POST
requests should be treated. See
.postAction
PostCreate [Text] | Treat |
PostCreateRedir [Text] | Treat |
PostProcess (HaltT m ()) | Treat |
PostProcessRedir (HaltT m ByteString) | Treat |
postCreate :: Monad m => [Text] -> m (PostAction m) Source
Create a PostAction
which performs resource creation without redirecting.
postCreateRedir :: Monad m => [Text] -> m (PostAction m) Source
Create a PostAction
which performs resource creation and redirects.
postProcess :: Monad m => HaltT m () -> m (PostAction m) Source
Create a PostAction
which runs some process and does not redirect.
postProcessRedir :: Monad m => HaltT m ByteString -> m (PostAction m) Source
Create a PostAction
which runs some process and does redirects.
Monad transformer for
functions which can halt the request
processing early with an error or some other response. Values are created with
the smart constructors Resource
and werror
.halt
MonadTrans HaltT Source | |
MonadState s m => MonadState s (HaltT m) Source | |
MonadReader r m => MonadReader r (HaltT m) Source | |
MonadWriter w m => MonadWriter w (HaltT m) Source | |
Monad m => Monad (HaltT m) Source | |
Monad m => Functor (HaltT m) Source | |
Monad m => Applicative (HaltT m) Source | |
MonadThrow m => MonadThrow (HaltT m) Source | |
MonadCatch m => MonadCatch (HaltT m) Source | |
MonadIO m => MonadIO (HaltT m) Source |
halt :: Monad m => Status -> HaltT m a Source
Immediately end processing of the request, returning the response
Status
. It is the responsibility of the resource to ensure that all
necessary response header and body elements have been added in
order to make that response code valid.
werror :: Monad m => ByteString -> HaltT m a Source
Immediately end processing of this request, returning a
500 Internal Server Error
response. The response body will contain the
reason.
werrorWith :: Monad m => Status -> ByteString -> HaltT m a Source
Immediately end processing of this request, returning a response
with the given Status
. The response body will contain the reason.
getDispatchPath :: (MonadState s m, HasReqData s) => m [Text] Source
The “local” path of the resource URI; the part after any prefix used in dispatch configuration. Of the three path accessors, this is the one you usually want. This is also the one that will change after postAction is called in your resource.
Container used to keep track of the decision state and what is known about response while processing a request.
HasReqData ReqData Source | |
Monad m => MonadState ReqData (WebcrankT m) Source |
Charsets
type Charset = CI ByteString Source
Character set type, e.g. utf-8. See
.charsetsProvided
data CharsetsProvided Source
Indicates whether the resource supports multiple character sets
or not. See charsetsProvided
NoCharset | Indicates that the resource doesn't support any additional character sets, all responses from the resource will have the same character set, regardless of what the client requests. |
CharsetsProvided (NonEmpty (Charset, Body -> Body)) | The character sets the resource supports along with functions for converting the response body. |
provideCharsets :: Monad m => NonEmpty (Charset, Body -> Body) -> m CharsetsProvided Source
Shortcut for return . CharsetsProvided
Headers
type HeadersMap = HashMap HeaderName [ByteString] Source
addResponseHeader :: (MonadState s m, HasReqData s) => HeaderName -> ByteString -> m () Source
Add a header to the response.
putResponseHeader :: (MonadState s m, HasReqData s) => HeaderName -> ByteString -> m () Source
Replace any existing response headers for the header name with the new value.
Body
type Body = ByteString Source
Response body type.
lazyByteStringBody :: ByteString -> Body Source
Create a response Body
from a lazy ByteString
.
byteStringBody :: ByteString -> Body Source
Create a response Body
from a ByteString
.
lazyTextBody :: Text -> Body Source
Create a response Body
from lazy Text
.
writeBody :: (MonadState s m, HasReqData s) => ByteString -> m () Source
Use the Body
as the response body.
writeLBS :: (MonadState s m, HasReqData s) => ByteString -> m () Source
Use the lazy ByteString
as the response body.
writeBS :: (MonadState s m, HasReqData s) => ByteString -> m () Source
Use the ByteString
as the response body.
writeLT :: (MonadState s m, HasReqData s) => Text -> m () Source
Use the lazy Text
as the response body.
writeText :: (MonadState s m, HasReqData s) => Text -> m () Source
Use the Text
as the response body.
writeStr :: (MonadState s m, HasReqData s) => String -> m () Source
Use the String
as the response body.
Extra convience (re)exports
module Network.HTTP.Date
module Network.HTTP.Media
module Network.HTTP.Types