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 -- |A 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 -- |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 , cnfExtToMIMEType = defaultExtensionMap