om-http-0.3.0.1: Http utilities.
Safe HaskellSafe-Inferred
LanguageHaskell2010

OM.HTTP

Description

Miscellaneous HTTP Utilities.

Synopsis

Documentation

runTlsRedirect Source #

Arguments

:: (Loc -> LogSource -> LogLevel -> LogStr -> IO ())

Logging backend.

-> ByteString

Server name.

-> Version

Server version.

-> ByteString

Target URL.

-> IO () 

Runs a web server on port 80, that redirects to the given url. Does request logging, and sets the HSTS Directive header, and in the unlikely event of excptions it will also catch and log them.

requestLogging :: (Loc -> LogSource -> LogLevel -> LogStr -> IO ()) -> Middleware Source #

Logs an HTTP request by emitting two log messages. The first messages logs that the request has begun. The second messages logs the status result and timing of the request once it is finished.

Starting request: GET /foo
GET /foo --> 200 Ok (0.001s)

This can help debugging requests that hang or crash for whatever reason.

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

Set the Server: header.

insertResponseHeaderIfMissing :: Header -> Middleware Source #

Insert a response header only if it has not already been inserted.

overwriteResponseHeader :: Header -> Middleware Source #

Inserts a response header, clobbering any and all existing values for the given header.

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

The content-type of the files being served will be guessed using defaultMimeLookup.

logExceptionsAndContinue Source #

Arguments

:: (Loc -> LogSource -> LogLevel -> LogStr -> IO ())

Logging backend.

-> Middleware 

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.

sshConnect :: Middleware Source #

Middleware that provides an HTTP CONNECT passthrough to the local ssh port. Useful primarily for bypassing content-inspection firewalls.

staticPage Source #

Arguments

:: [Text]

The path info.

-> ByteString

The content type.

-> ByteString

The response body content.

-> Middleware 

Serve a static page at the given pathInfo.

defaultIndex :: Middleware Source #

Rewrite: "/" -> "/index.html".

newtype BearerToken Source #

A bearer token, which is an instance of the necessary type classes to be useful as a servant header value.

Constructors

BearerToken 

Fields