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