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.
- runHttpd :: HostMapper α => Config -> α -> IO ()
- module Network.HTTP.Lucu.Config
- type Host = CI Text
- type Path = [PathSegment]
- module Network.HTTP.Lucu.Dispatcher
- module Network.HTTP.Lucu.Resource
- data Method
- module Network.HTTP.Lucu.Response.StatusCode
- module Network.HTTP.Lucu.Abortion
- data ETag = ETag {
- etagIsWeak :: !Bool
- etagToken :: !Ascii
- strongETag :: Ascii -> ETag
- weakETag :: Ascii -> ETag
- data MIMEType = MIMEType {}
- data MIMEParams
- mimeType :: QuasiQuoter
- data AuthChallenge = BasicAuthChallenge !Realm
- data AuthCredential = BasicAuthCredential !UserID !Password
- module Network.HTTP.Lucu.StaticFile
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 ::
FIXME: use monad-parallel's MonadFork instead of IO.
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!"
}
Config
uration
module Network.HTTP.Lucu.Config
URI-related data types
type Path = [PathSegment]Source
Path
is a list of URI path segments.
Resource
dispatcher
module Network.HTTP.Lucu.Dispatcher
Rsrc
Monad
module Network.HTTP.Lucu.Resource
Things to be used in the Resource monad
Method
Definition of HTTP request methods.
StatusCode
Abortion
module Network.HTTP.Lucu.Abortion
ETag
An entity tag consists of a weakness flag and an opaque string.
ETag | |
|
strongETag :: Ascii -> ETagSource
MIME Type
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 |
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).
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) |
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
.
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
.
Eq AuthCredential | |
Show AuthCredential | |
Default (Parser AuthCredential) |
Utilities
Static file handling
module Network.HTTP.Lucu.StaticFile