canteven-http-0.1.5.1: Utilities for HTTP programming.

Safe HaskellNone
LanguageHaskell2010

Canteven.HTTP

Description

This module provides some utilities that make for better HTTP-based programs.

Synopsis

Documentation

class FromEntity e where Source #

The class of things that can be read as http message entities.

Minimal complete definition

decodeEntity

Methods

decodeEntity :: Maybe ContentType -> ByteString -> DecodeResult e Source #

Decode the entity, according to the specified content type.

class ToEntity e where Source #

The class of things that can be used to generate http message entities.

Minimal complete definition

getContentType, getBytes

Methods

getContentType :: e -> ContentType Source #

The content type of the respone entity.

getBytes :: e -> ByteString Source #

The bytes associated with the response entity.

data DecodeResult e Source #

The result of trying to decode a request entity.

Constructors

Unsupported

Signifies an unsupported content type.

BadEntity String

Signifies that the request entity is invalid, and provides some kind of reason why.

Ok e

Successfully decoded the entity.

Instances

type ContentType = ByteString Source #

ContentType is an alias for ByteString.

requestLogging :: LoggerTImpl -> Middleware Source #

This request logger is better than the ones in RequestLogger, where "better" means:

1) Operates in MonadLogger. 2) Logs the start of a request separate from its completion. 3) Logs the duration of the request.

logExceptionsAndContinue :: LoggerTImpl -> Middleware Source #

Logs all exceptions, and returns a 500 Internal Server error.

This is useful because your wai framework won't always do what you expect when it encounters random exceptions. For instance, an exception thrown in IO may cause functionality of higher-level middlewares to be bypassed unless they know how to catch and re-throw exceptions (making them more complicated). This middleware explicitly will not re-throw exceptions, unless those exceptions were encountered after the headers have already been sent, e.g. when using StreamingBody.

What it will do is generate a unique id for the exception and print that ID, so you can easily find it in the logs.

setServer :: Text -> Version -> Middleware Source #

Set the Server: header.

Since: 0.1.2

staticSite :: FilePath -> Q (TExp Middleware) Source #

The Template-Haskell splice $$(staticSite dir) will build a Middleware that serves a set of static files determined at compile time, or else passes the request to the underlying Application.

All files under dir will be served relative to the root path of your web server, so the file <dir>/foo/bar.html will be served at http://your-web-site.com/foo/bar.html

Since: 0.1.3