Lucu-1.0: Embedded HTTP Server

Network.HTTP.Lucu

Contents

Description

Lucu is an embedded HTTP server library.

Features:

Affinity for RESTafarians
Lucu is specifically designed to be suitable for RESTful applications.
Full support of HTTP/1.1
Lucu supports request pipelining, chunked I/O, ETag comparison and "100 Continue".
SSL connections
Lucu can handle HTTP connections over Secure Socket Layer when configured with -fssl flag.

Lucu is not a replacement for Apache or lighttpd. It is intended to be used to build an efficient web-based RESTful application which runs behind a reverse-proxy so it doesn't have the following (otherwise essential) functionalities:

Logging
Lucu doesn't write logs of any requests from any clients.
Client Filtering
Lucu always accepts any clients. No IP filter is implemented.
Bandwidth Limitting
Lucu doesn't limit bandwidth it consumes.
Protection Against Wicked Clients
Lucu is somewhat fragile against wicked clients. No attacker should be able to cause a buffer-overflow but can possibly DoS it.

Synopsis

Entry Point

runHttpd :: HostMapper α => Config -> α -> IO ()Source

This is the entry point of Lucu httpd. It listens to a socket and waits for clients. runHttpd never stops by itself so the only way to stop it is to raise an exception in the thread running it.

Example:

{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} module Main where import qualified Data.Collections as C import Network import Network.HTTP.Lucu main :: IO () main = let config = defaultConfig tree :: ResourceTree tree = C.fromList [ ([], nonGreedy helloWorld) ] in Network.withSocketsDo . runHttpd config $ resourceMap tree helloWorld :: Network.HTTP.Lucu.Resource helloWorld = C.fromList [ ( Network.HTTP.Lucu.GET , do Network.HTTP.Lucu.setContentType [Network.HTTP.Lucu.mimeType| text/plain |] Network.HTTP.Lucu.putChunk "Hello, world!" } FIXME: use monad-parallel's MonadFork instead of IO.

Configuration

URI-related data types

type Host = CI TextSource

Host represents an IP address or a host name in an URI authority.

type Path = [PathSegment]Source

Path is a list of URI path segments.

Resource dispatcher

Rsrc Monad

Things to be used in the Resource monad

Method

data Method Source

Definition of HTTP request methods.

Instances

Eq Method 
Show Method 
Collection Resource (Method, Rsrc ()) 
Unfoldable Resource (Method, Rsrc ()) 
Foldable Resource (Method, Rsrc ()) 
Default (Parser Method) 

StatusCode

Abortion

ETag

data ETag Source

An entity tag consists of a weakness flag and an opaque string.

Constructors

ETag 

Fields

etagIsWeak :: !Bool

The weakness flag. Weak tags looks like W/"blahblah" and strong tags are like "blahblah". See: http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.3.3

etagToken :: !Ascii

An opaque string. Only characters from 0x20 (sp) to 0x7e (~) are allowed.

Instances

Eq ETag 
Data ETag 
Show ETag 
Typeable ETag 
Lift ETag 
ConvertSuccess ETag Ascii 
ConvertSuccess ETag AsciiBuilder 
ConvertAttempt ETag Ascii 
ConvertAttempt ETag AsciiBuilder 
Default (Parser [ETag]) 
Default (Parser ETag) 

strongETag :: Ascii -> ETagSource

This is equivalent to ETag False. If you want to generate an ETag from a file, try using Network.HTTP.Lucu.StaticFile.generateETagFromFile.

weakETag :: Ascii -> ETagSource

This is equivalent to ETag True.

MIME Type

data MIMEType Source

A media type, subtype, and parameters.

Constructors

MIMEType 

Instances

Eq MIMEType 
Read MIMEType 
Show MIMEType 
Typeable MIMEType 
Lift MIMEType 
ConvertSuccess MIMEType Ascii 
ConvertSuccess MIMEType AsciiBuilder 
ConvertAttempt Ascii MIMEType

Parse MIMEType from an Ascii. For MIME type literals, consider using mimeType quasi-quoter.

ConvertAttempt MIMEType Ascii 
ConvertAttempt MIMEType AsciiBuilder 
Default (Parser [MIMEType]) 
Default (Parser MIMEType) 

data MIMEParams Source

A Map from MIME parameter attributes to values. Attributes are always case-insensitive according to RFC 2045 (http://tools.ietf.org/html/rfc2045#section-5.1).

Instances

Eq MIMEParams 
Read MIMEParams 
Show MIMEParams 
Typeable MIMEParams 
Monoid MIMEParams 
Lift MIMEParams 
ConvertSuccess MIMEParams Ascii 
ConvertSuccess MIMEParams AsciiBuilder 
ConvertAttempt MIMEParams Ascii 
ConvertAttempt MIMEParams AsciiBuilder 
Map MIMEParams CIAscii Text 
Indexed MIMEParams CIAscii Text 
Collection MIMEParams (CIAscii, Text) 
Unfoldable MIMEParams (CIAscii, Text) 
Foldable MIMEParams (CIAscii, Text) 
SortingCollection MIMEParams (CIAscii, Text) 
Default (Parser MIMEParams) 

mimeType :: QuasiQuoterSource

QuasiQuoter for MIMEType literals.

   textPlain :: MIMEType
   textPlain = [mimeType| text/plain; charset="UTF-8" |]

Authentication

data AuthChallenge Source

Authentication challenge to be sent to clients with "WWW-Authenticate" header field. See Network.HTTP.Lucu.setWWWAuthenticate.

Constructors

BasicAuthChallenge !Realm 

Instances

Eq AuthChallenge 
ConvertSuccess AuthChallenge Ascii 
ConvertSuccess AuthChallenge AsciiBuilder 
ConvertAttempt AuthChallenge Ascii 
ConvertAttempt AuthChallenge AsciiBuilder 

data AuthCredential Source

Authorization credential to be sent by client with "Authorization" header. See Network.HTTP.Lucu.getAuthorization.

Instances

Utilities

Static file handling