Safe Haskell | None |
---|---|
Language | Haskell2010 |
- enterAction :: forall s e. (Show e, Typeable e) => s -> ActionState -> (ActionError e -> IO ServantErr) -> Maybe ThentosSessionToken -> Action e s :~> ExceptT ServantErr IO
- newtype ErrorMessage = ErrorMessage {
- fromErrorMessage :: ST
- mkServantErr :: ServantErr -> ST -> ServantErr
- type ErrorInfo a = (Maybe (Priority, String), ServantErr, a)
- errorInfoToServantErr :: (ServantErr -> a -> ServantErr) -> ErrorInfo a -> IO ServantErr
- baseActionErrorToServantErr :: ActionError Void -> IO ServantErr
- actionErrorInfo :: Show e => (ThentosError e -> ErrorInfo ST) -> ActionError e -> ErrorInfo ST
- thentosErrorInfo :: Show e => (e -> ErrorInfo ST) -> ThentosError e -> ErrorInfo ST
- data Post200 contentTypes a
- data ThentosHeaderName
- type RenderHeaderFun = ThentosHeaderName -> CI SBS
- lookupThentosHeader :: RenderHeaderFun -> Request -> ThentosHeaderName -> Maybe ST
- lookupThentosHeaderSession :: RenderHeaderFun -> Request -> Maybe ThentosSessionToken
- lookupThentosHeaderService :: RenderHeaderFun -> Request -> Maybe ServiceId
- renderThentosHeaderName :: RenderHeaderFun
- badHeaders :: [Header] -> [Header]
- clearCustomHeaders :: RenderHeaderFun -> RequestHeaders -> RequestHeaders
- data ThentosAssertHeaders
- contentTypeJsonHeader :: Header
- httpCachePolicy :: ResponseHeaders
- addCacheControlHeaders :: Middleware
- addHeadersToResponse :: ResponseHeaders -> Response -> Response
- data CorsPolicy = CorsPolicy {
- corsHeaders :: SBS
- corsMethods :: SBS
- corsOrigin :: SBS
- addCorsHeaders :: CorsPolicy -> Middleware
- runWarpWithCfg :: HttpConfig -> Application -> IO ()
- loggerMW :: Middleware
action
enterAction :: forall s e. (Show e, Typeable e) => s -> ActionState -> (ActionError e -> IO ServantErr) -> Maybe ThentosSessionToken -> Action e s :~> ExceptT ServantErr IO
error handling
newtype ErrorMessage
ErrorMessage | |
|
Eq ErrorMessage | |
Show ErrorMessage | |
ToJSON ErrorMessage |
mkServantErr :: ServantErr -> ST -> ServantErr
Construct a ServantErr that looks as our errors should.
Status code and reason phrase are taken from the base error given as first argument.
The message given as second argument is wrapped into a ErrorMessage
JSON object.
type ErrorInfo a = (Maybe (Priority, String), ServantErr, a)
errorInfoToServantErr :: (ServantErr -> a -> ServantErr) -> ErrorInfo a -> IO ServantErr
Log things, and construct a ServantErr
.
If any logging is to take place, it should take place here, not near the place where the error is thrown.
baseActionErrorToServantErr :: ActionError Void -> IO ServantErr
actionErrorInfo :: Show e => (ThentosError e -> ErrorInfo ST) -> ActionError e -> ErrorInfo ST
thentosErrorInfo :: Show e => (e -> ErrorInfo ST) -> ThentosError e -> ErrorInfo ST
custom servers for servant
data Post200 contentTypes a
request headers
data ThentosHeaderName
Bounded ThentosHeaderName | |
Enum ThentosHeaderName | |
Eq ThentosHeaderName | |
Ord ThentosHeaderName | |
Read ThentosHeaderName | |
Show ThentosHeaderName |
type RenderHeaderFun = ThentosHeaderName -> CI SBS
lookupThentosHeader :: RenderHeaderFun -> Request -> ThentosHeaderName -> Maybe ST
lookupThentosHeaderSession :: RenderHeaderFun -> Request -> Maybe ThentosSessionToken
lookupThentosHeaderService :: RenderHeaderFun -> Request -> Maybe ServiceId
badHeaders :: [Header] -> [Header]
Filter header list for all headers that start with X-Thentos-, but don't correspond to
the default rendering of any ThentosHeaderName
.
clearCustomHeaders :: RenderHeaderFun -> RequestHeaders -> RequestHeaders
Remove all headers matched by a RenderHeaderFun
. This is useful if the request is to be
used as a basis for e.g. constructing another request to a proxy target.
data ThentosAssertHeaders
Make sure that all thentos headers are good (badHeaders
yields empty list).
HasLink * sub => HasLink * ((:>) * * ThentosAssertHeaders sub) | |
HasServer * subserver => HasServer * ((:>) * * ThentosAssertHeaders subserver) | |
type MkLink * ((:>) * * ThentosAssertHeaders sub) = MkLink * sub | |
type ServerT * ((:>) * * ThentosAssertHeaders subserver) m = ServerT * subserver m | |
type Foreign ((:>) * * ThentosAssertHeaders sub) = Foreign sub |
response headers
contentTypeJsonHeader :: Header
header setting the Content-Type to JSON.
httpCachePolicy :: ResponseHeaders
Cache-control headers in HTTP responses. This is currently just a constant list of headers.
FUTURE WORK: We may want for this to come from Thentos.Config. We may also want to the policy to be a function in the request for which the response is constructed. Not sure how best to combine these two requirements.
addCacheControlHeaders :: Middleware
Add suitable cache-control headers to HTTP responses. For now, this just prevents caching of all GET/HEAD requests (other HTTP methods are considered uncacheable by default). In the future we may use more refined caching strategies.
addHeadersToResponse :: ResponseHeaders -> Response -> Response
data CorsPolicy
Policy for Cross-origin Resource Sharing (CORS).
CorsPolicy | |
|
addCorsHeaders :: CorsPolicy -> Middleware
Add "Access-Control-Allow-..." headers based on a CorsPolicy
.
warp & wai
runWarpWithCfg :: HttpConfig -> Application -> IO ()
loggerMW :: Middleware