Safe Haskell | None |
---|---|
Language | Haskell2010 |
OM.HTTP
Description
Miscellaneous HTTP Utilities.
Synopsis
- runTlsRedirect :: (Loc -> LogSource -> LogLevel -> LogStr -> IO ()) -> ByteString -> Version -> ByteString -> IO ()
- hstsDirective :: NominalDiffTime -> Middleware
- requestLogging :: (Loc -> LogSource -> LogLevel -> LogStr -> IO ()) -> Set HeaderName -> Middleware
- setServer :: ByteString -> Version -> Middleware
- insertResponseHeaderIfMissing :: Header -> Middleware
- overwriteResponseHeader :: Header -> Middleware
- staticSite :: FilePath -> Q (TExp Middleware)
- logExceptionsAndContinue :: (Loc -> LogSource -> LogLevel -> LogStr -> IO ()) -> Middleware
- sshConnect :: Middleware
- staticPage :: [Text] -> ByteString -> ByteString -> Middleware
- defaultIndex :: Middleware
- newtype BearerToken = BearerToken {}
- emptyApp :: Application
Documentation
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.
hstsDirective :: NominalDiffTime -> Middleware Source #
Inject the HSTS directives, see https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security.
Arguments
:: (Loc -> LogSource -> LogLevel -> LogStr -> IO ()) | |
-> Set HeaderName | Headers to redact |
-> Middleware |
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.
{"text":"Starting request: GET /api/me","meta":{..<request details>..}} {"text":"Request complete: GET /api/me","meta":{"status":"200 OK","time":"0.000370671s"}}
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 #
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.
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 |
Instances
ToHttpApiData BearerToken Source # | |
Defined in OM.HTTP Methods toUrlPiece :: BearerToken -> Text # toEncodedUrlPiece :: BearerToken -> Builder # toHeader :: BearerToken -> ByteString # toQueryParam :: BearerToken -> Text # |
emptyApp :: Application Source #
A WAI Application
that returns 404 not found for everything.