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