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