]> gitweb @ CieloNegro.org - Lucu.git/blob - Network/HTTP/Lucu/Config.hs
Documentation
[Lucu.git] / Network / HTTP / Lucu / Config.hs
1 -- |Configurations for the Lucu httpd like a port to listen.
2 module Network.HTTP.Lucu.Config
3     ( Config(..)
4     , defaultConfig
5     )
6     where
7
8 import qualified Data.Map as M
9 import           Data.Map (Map)
10 import           Network
11 import           Network.BSD
12 import           Network.HTTP.Lucu.MIMEType
13 import           Network.HTTP.Lucu.MIMEType.DefaultExtensionMap
14 import           System.IO.Unsafe
15
16 -- |A configuration record for the Lucu httpd. You need to use
17 -- 'defaultConfig' or setup your own configuration to run the httpd.
18 data Config = Config {
19     -- |A string which will be sent to clients as \"Server\" field.
20       cnfServerSoftware       :: String
21     -- |The host name of the server. This value will be used in
22     -- built-in pages like \"404 Not Found\".
23     , cnfServerHost           :: HostName
24     -- |A port ID to listen to HTTP clients.
25     , cnfServerPort           :: PortID
26     -- |The maximum number of requests to accept in one connection
27     -- simultaneously. If a client exceeds this limitation, its last
28     -- request won't be processed until a response for its earliest
29     -- pending request is sent back to the client.
30     , cnfMaxPipelineDepth     :: Int
31     -- |The maximum length of request entity to accept in bytes. Note
32     -- that this is nothing but the default value which is used when
33     -- 'Network.HTTP.Lucu.Resource.input' and such like are applied to
34     -- 'Network.HTTP.Lucu.Resource.defaultLimit', so there is no
35     -- guarantee that this value always constrains all the requests.
36     , cnfMaxEntityLength      :: Int
37     -- |The maximum length of chunk to output. This value is used by
38     -- 'Network.HTTP.Lucu.Resource.output' and such like to limit the
39     -- chunk length so you can safely output an infinite string (like
40     -- a lazy stream of \/dev\/random) using those actions.
41     , cnfMaxOutputChunkLength :: Int
42     -- |A mapping from extension to MIME Type. This value is used by
43     -- 'Network.HTTP.Lucu.StaticFile.staticFile' to guess the MIME
44     -- Type of static files. Note that MIME Types are currently
45     -- guessed only by file name. 
46     -- 
47     -- Guessing by file magic is indeed a wonderful idea but that is
48     -- not implemented (yet). But hey, don't you think it's better a
49     -- file system got a MIME Type as a part of inode? Or it might be
50     -- a good idea to use GnomeVFS
51     -- (<http://developer.gnome.org/doc/API/2.0/gnome-vfs-2.0/>)
52     -- instead of vanilla FS.
53     , cnfExtToMIMEType        :: Map String MIMEType
54     }
55
56 -- |The default configuration. Generally you can use this value as-is,
57 -- or possibly you just want to replace the 'cnfServerSoftware' and
58 -- 'cnfServerPort'.
59 defaultConfig :: Config
60 defaultConfig = Config {
61                   cnfServerSoftware       = "Lucu/1.0"
62                 , cnfServerHost           = unsafePerformIO getHostName
63                 , cnfServerPort           = Service "http"
64                 , cnfMaxPipelineDepth     = 100
65                 , cnfMaxEntityLength      = 16 * 1024 * 1024 -- 16 MiB
66                 , cnfMaxOutputChunkLength = 5 * 1024 * 1024  -- 5 MiB
67                 , cnfExtToMIMEType        = defaultExtensionMap
68                 }