Lucu-1.0: Embedded HTTP Server




Lucu is an embedded HTTP server library.


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:

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.


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.


{-# 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.


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


data Method Source

Definition of HTTP request methods.


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




data ETag Source

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




etagIsWeak :: !Bool

The weakness flag. Weak tags looks like W/"blahblah" and strong tags are like "blahblah". See:

etagToken :: !Ascii

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


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.


data MIMEType Source

A media type, subtype, and parameters.




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 (


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" |]


data AuthChallenge Source

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


BasicAuthChallenge !Realm 


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.



Static file handling