Lucu-1.0: Embedded HTTP Server

Network.HTTP.Lucu.Dispatcher

Description

Static and dynamic repositories of resources in an httpd.

Synopsis

Documentation

class HostMapper α whereSource

Class of maps from Host to ResourceMap to provide name-based virtual hosts.

Note that Lucu currently does not implement neither RFC 2817 connection upgrading (http://tools.ietf.org/html/rfc2817) nor RFC 3546 server name indication (http://tools.ietf.org/html/rfc3546#section-3.1) so you won't be able to host more than one SSL virtual host on the same port without using wildcard certificates (http://tools.ietf.org/html/rfc2818#section-3.1).

Minimal complete definition: findResourceMap

Methods

findResourceMap :: Host -> α -> MaybeT IO ResourceMapSource

Find a repository of resources for the given host name if any.

hostMap :: α -> HostMapSource

Wrap an instance of HostMapper in a monoidal, homogeneous container.

Instances

Map α Host ResourceMap => HostMapper α

Any Maps from Host to ResourceMap are also HostMappers.

HostMapper ResourceMap

ResourceMaps are also HostMappers too, which matches to any hosts.

HostMapper HostMap 
HostMapper (Host -> Maybe ResourceMap)

A pure host mapper.

HostMapper (Host -> MaybeT IO ResourceMap)

An IO-based host mapper.

data HostMap Source

Container type for the HostMapper type class.

Instances

Monoid HostMap

mappend a b first tries a, and if it fails, tries b next.

HostMapper HostMap 
HostMapper α => Unfoldable HostMap α

insert a b first tries a, and if it fails, tries b next.

class ResourceMapper α whereSource

Class of maps from resource Path to Resource.

Minimal complete definition: findResource

Methods

findResource :: Path -> α -> MaybeT IO (Path, Resource)Source

Find a resource handler for the given resource path, along with the path where the said handler was found. The found path is usually the same as the queried path, but there are situations where the found path is just a prefix of the queried path. See greedy.

resourceMap :: α -> ResourceMapSource

Wrap an instance of ResourceMapper in a monoidal, homogeneous container.

Instances

Map α Path (Path, Resource) => ResourceMapper α

Any Maps from Path to (Path, Resource) are also ResourceMappers.

ResourceMapper ResourceTree

findResource performs the longest prefix match on the tree, finding the most specific one.

ResourceMapper ResourceMap 
ResourceMapper (Path -> Maybe (Path, Resource))

A pure resource mapper.

ResourceMapper (Path -> MaybeT IO (Path, Resource))

An IO-based resource mapper.

data ResourceMap Source

Container type for the ResourceMapper type class.

Instances

Monoid ResourceMap

mappend a b first tries a, and if it fails, tries b next.

ResourceMapper ResourceMap 
HostMapper ResourceMap

ResourceMaps are also HostMappers too, which matches to any hosts.

ResourceMapper α => Unfoldable ResourceMap α

insert a b first tries a, and if it fails, tries b next.

HostMapper (Host -> Maybe ResourceMap)

A pure host mapper.

HostMapper (Host -> MaybeT IO ResourceMap)

An IO-based host mapper.

data ResourceTree Source

ResourceTree is an opaque structure which a map from resource Path to ResourceNode.

   fromList [ ([]        , nonGreedy $ Network.HTTP.Lucu.StaticFile.staticFile "/usr/include/stdio.h" ) -- /
            , (["unistd"], nonGreedy $ Network.HTTP.Lucu.StaticFile.staticFile "/usr/include/unistd.h") -- /unistd
            ]

Note that path segments are always represented as octet streams in this system. Lucu automatically decodes percent-encoded URIs but has no involvement in character encodings such as UTF-8, since RFC 2616 (HTTP/1.1) says nothing about character encodings to be used in "http" and "https" URI schemas.

Instances

Monoid ResourceTree 
ResourceMapper ResourceTree

findResource performs the longest prefix match on the tree, finding the most specific one.

Collection ResourceTree (Path, ResourceNode) 
Unfoldable ResourceTree (Path, ResourceNode) 
Foldable ResourceTree (Path, ResourceNode) 

data ResourceNode Source

A node of Resource located somewhere in a ResourceTree. Such nodes are either greedy or nonGreedy.

Instances

greedy :: Resource -> ResourceNodeSource

Make a greedy resource node.

Say a client is trying to access "/aaa/bbb/ccc' while there is no resource node at the path. If there are greedy resource nodes at "/aaa/bbb", "/aaa" or "/" they will be chosen instead as a fallback. Greedy resource nodes are searched in depth-first order, just like CGI scripts.

nonGreedy :: Resource -> ResourceNodeSource

Make a normal, non-greedy resource node.