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