]> gitweb @ CieloNegro.org - Lucu.git/blob - Network/HTTP/Lucu/Config.hs
Exodus to GHC 6.8.1
[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.ByteString as Strict (ByteString)
9 import qualified Data.ByteString.Char8 as C8 hiding (ByteString)
10 import           Network
11 import           Network.BSD
12 import           Network.HTTP.Lucu.MIMEType.Guess
13 import           Network.HTTP.Lucu.MIMEType.DefaultExtensionMap
14 import           System.IO.Unsafe
15
16 -- |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 :: !Strict.ByteString
21     -- |The host name of the server. This value will be used in
22     -- built-in pages like \"404 Not Found\".
23     , cnfServerHost :: !Strict.ByteString
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     -- | Whether to dump too late abortion to the stderr or not. See
43     -- 'Network.HTTP.Lucu.Abortion.abort'.
44     , cnfDumpTooLateAbortionToStderr :: !Bool
45     -- |A mapping from extension to MIME Type. This value is used by
46     -- 'Network.HTTP.Lucu.StaticFile.staticFile' to guess the MIME
47     -- Type of static files. Note that MIME Types are currently
48     -- guessed only by file name. 
49     -- 
50     -- Guessing by file magic is indeed a wonderful idea but that is
51     -- not implemented (yet). But, don't you think it's better a file
52     -- system got a MIME Type as a part of inode? Or it might be a
53     -- good idea to use GnomeVFS
54     -- (<http://developer.gnome.org/doc/API/2.0/gnome-vfs-2.0/>)
55     -- instead of vanilla FS.
56     , cnfExtToMIMEType :: !ExtMap
57     }
58
59 -- |The default configuration. Generally you can use this value as-is,
60 -- or possibly you just want to replace the 'cnfServerSoftware' and
61 -- 'cnfServerPort'.
62 defaultConfig :: Config
63 defaultConfig = Config {
64                   cnfServerSoftware              = C8.pack "Lucu/1.0"
65                 , cnfServerHost                  = C8.pack (unsafePerformIO getHostName)
66                 , cnfServerPort                  = Service "http"
67                 , cnfMaxPipelineDepth            = 100
68                 , cnfMaxEntityLength             = 16 * 1024 * 1024 -- 16 MiB
69                 , cnfMaxOutputChunkLength        = 5 * 1024 * 1024  -- 5 MiB
70                 , cnfDumpTooLateAbortionToStderr = True
71                 , cnfExtToMIMEType               = defaultExtensionMap
72                 }