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