]> gitweb @ CieloNegro.org - Lucu.git/blob - Network/HTTP/Lucu/Config.hs
Code cleanup (preparation for ditz/lucu-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     , SSLConfig(..)
5     , defaultConfig
6     )
7     where
8
9 import qualified Data.ByteString as Strict (ByteString)
10 import qualified Data.ByteString.Char8 as C8 hiding (ByteString)
11 import           Network
12 import           Network.BSD
13 import           Network.HTTP.Lucu.MIMEType.Guess
14 import           Network.HTTP.Lucu.MIMEType.DefaultExtensionMap
15 import           OpenSSL.Session
16 import           System.IO.Unsafe
17
18 -- |Configuration record for the Lucu httpd. You need to use
19 -- 'defaultConfig' or setup your own configuration to run the httpd.
20 data Config = Config {
21
22     -- |A string which will be sent to clients as \"Server\" field.
23       cnfServerSoftware :: !Strict.ByteString
24
25     -- |The host name of the server. This value will be used in
26     -- built-in pages like \"404 Not Found\".
27     , cnfServerHost :: !Strict.ByteString
28
29     -- |A port ID to listen to HTTP clients.
30     , cnfServerPort :: !PortID
31
32     -- |Configuration for HTTPS connections. Set this 'Nothing' to
33     -- disable HTTPS.
34     , cnfSSLConfig :: !(Maybe SSLConfig)
35
36     -- |The maximum number of requests to accept in one connection
37     -- simultaneously. If a client exceeds this limitation, its last
38     -- request won't be processed until a response for its earliest
39     -- pending request is sent back to the client.
40     , cnfMaxPipelineDepth :: !Int
41
42     -- |The maximum length of request entity to accept in bytes. Note
43     -- that this is nothing but the default value which is used when
44     -- 'Network.HTTP.Lucu.Resource.input' and such like are applied to
45     -- 'Network.HTTP.Lucu.Resource.defaultLimit', so there is no
46     -- guarantee that this value always constrains all the requests.
47     , cnfMaxEntityLength :: !Int
48
49     -- |The maximum length of chunk to output. This value is used by
50     -- 'Network.HTTP.Lucu.Resource.output' and such like to limit the
51     -- chunk length so you can safely output an infinite string (like
52     -- a lazy stream of \/dev\/random) using those actions.
53     , cnfMaxOutputChunkLength :: !Int
54
55     -- | Whether to dump too late abortion to the stderr or not. See
56     -- 'Network.HTTP.Lucu.Abortion.abort'.
57     , cnfDumpTooLateAbortionToStderr :: !Bool
58
59     -- |A mapping from extension to MIME Type. This value is used by
60     -- 'Network.HTTP.Lucu.StaticFile.staticFile' to guess the MIME
61     -- Type of static files. Note that MIME Types are currently
62     -- guessed only by file name. 
63     -- 
64     -- Guessing by file magic is indeed a wonderful idea but that is
65     -- not implemented (yet). But, don't you think it's better a file
66     -- system got a MIME Type as a part of inode? Or it might be a
67     -- good idea to use GnomeVFS
68     -- (<http://developer.gnome.org/doc/API/2.0/gnome-vfs-2.0/>)
69     -- instead of vanilla FS.
70     , cnfExtToMIMEType :: !ExtMap
71     }
72
73 -- |Configuration record for HTTPS connections.
74 data SSLConfig
75     = SSLConfig {
76         -- |A port ID to listen to HTTPS clients.
77         sslServerPort :: !PortID
78         -- |An SSL context for accepting connections.
79       , sslContext    :: !SSLContext
80       }
81
82 -- |The default configuration. Generally you can use this value as-is,
83 -- or possibly you just want to replace the 'cnfServerSoftware' and
84 -- 'cnfServerPort'. SSL connections are disabled by default.
85 defaultConfig :: Config
86 defaultConfig = Config {
87                   cnfServerSoftware              = C8.pack "Lucu/1.0"
88                 , cnfServerHost                  = C8.pack (unsafePerformIO getHostName)
89                 , cnfServerPort                  = Service "http"
90                 , cnfSSLConfig                   = Nothing
91                 , cnfMaxPipelineDepth            = 100
92                 , cnfMaxEntityLength             = 16 * 1024 * 1024 -- 16 MiB
93                 , cnfMaxOutputChunkLength        = 5 * 1024 * 1024  -- 5 MiB
94                 , cnfDumpTooLateAbortionToStderr = True
95                 , cnfExtToMIMEType               = defaultExtensionMap
96                 }