]> gitweb @ CieloNegro.org - Lucu.git/blob - Network/HTTP/Lucu/Config.hs
Added a configuration flag -fssl to enable SSL support. (default: off)
[Lucu.git] / Network / HTTP / Lucu / Config.hs
1 {-# LANGUAGE
2     CPP
3   , OverloadedStrings
4   , UnicodeSyntax
5   #-}
6 -- |Configurations for the Lucu httpd.
7 module Network.HTTP.Lucu.Config
8     ( Config(..)
9 #if defined(HAVE_SSL)
10     , SSLConfig(..)
11 #endif
12     , defaultConfig
13     )
14     where
15 import Data.Ascii (Ascii)
16 import Data.Text (Text)
17 import qualified Data.Text as T
18 import Network
19 import Network.BSD
20 import Network.HTTP.Lucu.MIMEType.Guess
21 import Network.HTTP.Lucu.MIMEType.DefaultExtensionMap
22 #if defined(HAVE_SSL)
23 import OpenSSL.Session
24 #endif
25 import System.IO.Unsafe
26
27 -- |Configuration record for to run the httpd.
28 data Config = Config {
29
30     -- |A banner string to be sent to clients with \"Server\" response
31     -- header field.
32       cnfServerSoftware ∷ !Ascii
33
34     -- |The host name of the server. This value will be used in
35     -- built-in pages like \"404 Not Found\".
36     , cnfServerHost ∷ !Text
37
38     -- |A port number (or a service name) to listen to HTTP clients.
39     , cnfServerPort ∷ !ServiceName
40
41     -- |Local IPv4 address to listen to both HTTP and HTTPS
42     -- clients. Set this to @('Just' "0.0.0.0")@ if you want to accept
43     -- any IPv4 connections. Set this to 'Nothing' to disable IPv4.
44     , cnfServerV4Addr ∷ !(Maybe HostName)
45
46     -- |Local IPv6 address to listen to both HTTP and HTTPS
47     -- clients. Set this to @('Just' "::")@ if you want to accept any
48     -- IPv6 connections. Set this to 'Nothing' to disable IPv6. Note
49     -- that there is currently no ways to assign separate ports to
50     -- IPv4 and IPv6 server sockets (but I don't think that will be a
51     -- problem.)
52     , cnfServerV6Addr ∷ !(Maybe HostName)
53
54 #if defined(HAVE_SSL)
55     -- |Configuration for HTTPS connections. Set this 'Nothing' to
56     -- disable HTTPS.
57     , cnfSSLConfig ∷ !(Maybe SSLConfig)
58 #endif
59
60     -- |The maximum number of requests to simultaneously accept in one
61     -- connection. If a client exceeds this limitation, its last
62     -- request won't be processed until a response for its earliest
63     -- pending request is sent back to the client.
64     , cnfMaxPipelineDepth ∷ !Int
65
66     -- |The maximum length of request entity to accept in octets. Note
67     -- that this is nothing but a default value used by
68     -- 'Network.HTTP.Lucu.Resource.getForm' and such when they are
69     -- applied to 'Nothing', so there is no guarantee that this value
70     -- always constrains all the requests.
71     , cnfMaxEntityLength ∷ !Int
72
73     -- |Whether to dump too late abortions to the stderr or not. See
74     -- 'Network.HTTP.Lucu.Abortion.abort'.
75     , cnfDumpTooLateAbortionToStderr ∷ !Bool
76
77     -- |A mapping table from file extensions to MIME Types. This value
78     -- is used by 'Network.HTTP.Lucu.StaticFile.staticFile' to guess
79     -- the MIME Type of static files. Note that MIME Types are
80     -- currently guessed only by file name.
81     -- 
82     -- Guessing by file magic might be a good idea but that's not
83     -- implemented (yet).
84     , cnfExtToMIMEType ∷ !ExtMap
85     }
86
87 #if defined(HAVE_SSL)
88 -- |Configuration record for HTTPS connections.
89 data SSLConfig
90     = SSLConfig {
91         -- |A port number (or a service name) to listen to HTTPS
92         -- clients. Local addresses (both for IPv4 and IPv6) will be
93         -- derived from the parent 'Config'.
94         sslServerPort ∷ !ServiceName
95
96         -- |An SSL context for accepting connections. You must set it
97         -- up yourself with at least a server certification.
98       , sslContext ∷ !SSLContext
99       }
100 #endif
101
102 -- |The default configuration. Generally you can use this value as-is,
103 -- or possibly you just want to replace the 'cnfServerSoftware' and
104 -- 'cnfServerPort'. SSL connections are disabled by default.
105 defaultConfig ∷ Config
106 defaultConfig = Config {
107                   cnfServerSoftware              = "Lucu/1.0"
108                 , cnfServerHost                  = T.pack (unsafePerformIO getHostName)
109                 , cnfServerPort                  = "http"
110                 , cnfServerV4Addr                = Just "0.0.0.0"
111                 , cnfServerV6Addr                = Just "::"
112 #if defined(HAVE_SSL)
113                 , cnfSSLConfig                   = Nothing
114 #endif
115                 , cnfMaxPipelineDepth            = 100
116                 , cnfMaxEntityLength             = 16 * 1024 * 1024 -- 16 MiB
117                 , cnfDumpTooLateAbortionToStderr = True
118                 , cnfExtToMIMEType               = defaultExtensionMap
119                 }