lio-simple-0.0.2.2: LIO support for the Simple web framework

Safe HaskellTrustworthy

LIO.Web.Simple

Contents

Description

This module defines several instances needed to use LIO as the underlying monad with Web.Simple, the simple web framework. Additionally, we provide some middleware for executing apps in a safe manner.

LIO.Web.Simple.TCB defines several functions that can be used to execute LIO web applications with the Warp server.

Synopsis

Utilities for parsing request

body :: Label l => LIOController l r ByteStringSource

Parses a HTML form from the request body. It returns a list of Params as well as a list of Files, which are pairs mapping the name of a file form field to a FileInfo pointing to a temporary file with the contents of the

Reads and returns the body of the HTTP request.

Note: body function consumes the body from a Source IO Bytestring. Since the Request constructor is exposed by Network.Wai.Internal, it's important to disallow construction of such values when considering untrusted code.

parseForm :: Label l => LIOController l r ([Param], [(ByteString, FileInfo ByteString)])Source

Parses a HTML form from the request body. It returns a list of Params as well as a list of Files, which are pairs mapping the name of a file form field to a FileInfo pointing to a temporary file with the contents of the upload.

Currently only tursted code can read the file.

Middleware

browserLabelGuard :: MonadLIO l m => l -> SimpleMiddleware mSource

Middleware that ensures the Response from the application is readable by the client's browser (as determined by the result label of the app computation and the label of the browser). If the response is not readable by the browser, the middleware sends a 403 (unauthorized) response instead.

removeRequestHeaders :: Monad m => [HeaderName] -> SimpleMiddleware mSource

Remove certain headers from the request.

removeResponseHeaders :: Monad m => [HeaderName] -> SimpleMiddleware mSource

Remove certain headers from the response, e.g., Set-Cookie.

LIO applications

type SimpleLIOApplication p l = Priv p -> SimpleApplication (LIO l)Source

An LIO simple aplpication is an LIO computation mapping a set of privileges and request to a response. While privileges can be provided in terms of a e.g., Reader monad, in certain cases not having the privilege as part of the sate is cleaner.

type SimpleLIOMiddleware p l = SimpleLIOApplication p l -> SimpleLIOApplication p lSource

Simple LIO middleware.

type LIOController l s = ControllerT s (LIO l)Source

Controller with LIO as the underlying monad.

Relevant modules