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