thentos-core-0.0.1.1: The swiss army knife of privacy-preserving identity management

Safe HaskellNone
LanguageHaskell2010

Thentos.Backend.Core

Contents

Synopsis

action

error handling

newtype ErrorMessage

Constructors

ErrorMessage 

Fields

fromErrorMessage :: ST
 

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.

custom servers for servant

data Post200 contentTypes a

Instances

HasLink * (Post200 ctypes a) 
AllCTRender ctypes a => HasServer * (Post200 ctypes a) 
type MkLink * (Post200 ctypes a) = URI 
type ServerT * (Post200 ctypes a) m = m a 
type Foreign (Post200 ((:) * JSON ([] *)) a) = Req 

request headers

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).

Instances

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).

Constructors

CorsPolicy 

Fields

corsHeaders :: SBS
 
corsMethods :: SBS
 
corsOrigin :: SBS
 

addCorsHeaders :: CorsPolicy -> Middleware

Add "Access-Control-Allow-..." headers based on a CorsPolicy.

warp & wai

runWarpWithCfg :: HttpConfig -> Application -> IO ()

loggerMW :: Middleware

Write all requests and responses to log file with prio DEBUG. Since Response does not have a Show instance, only dump the showable parts.