]> gitweb @ CieloNegro.org - Lucu.git/blob - Network/HTTP/Lucu/Config.hs
examples/HelloWorld.hs fully works now.
[Lucu.git] / Network / HTTP / Lucu / Config.hs
1 {-# LANGUAGE
2     OverloadedStrings
3   , UnicodeSyntax
4   #-}
5 -- |Configurations for the Lucu httpd like a port to listen.
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 the Lucu httpd. You need to use
23 -- 'defaultConfig' or setup your own configuration to run the httpd.
24 data Config = Config {
25
26     -- |A string which will be sent to clients as \"Server\" 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 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 way to assign separate ports to IPv4
45     -- and IPv6 server sockets.
46     , cnfServerV6Addr ∷ !(Maybe HostName)
47
48     -- |Configuration for HTTPS connections. Set this 'Nothing' to
49     -- disable HTTPS.
50     , cnfSSLConfig ∷ !(Maybe SSLConfig)
51
52     -- |The maximum number of requests to accept in one connection
53     -- simultaneously. If a client exceeds this limitation, its last
54     -- request won't be processed until a response for its earliest
55     -- pending request is sent back to the client.
56     , cnfMaxPipelineDepth ∷ !Int
57
58     -- |The maximum length of request entity to accept in bytes. Note
59     -- that this is nothing but the default value which is used when
60     -- 'Network.HTTP.Lucu.Resource.input' and such like are applied to
61     -- 'Network.HTTP.Lucu.Resource.defaultLimit', so there is no
62     -- guarantee that this value always constrains all the requests.
63     , cnfMaxEntityLength ∷ !Int
64
65     -- | Whether to dump too late abortion to the stderr or not. See
66     -- 'Network.HTTP.Lucu.Abortion.abort'.
67     , cnfDumpTooLateAbortionToStderr ∷ !Bool
68
69     -- |A mapping from extension to MIME Type. This value is used by
70     -- 'Network.HTTP.Lucu.StaticFile.staticFile' to guess the MIME
71     -- Type of static files. Note that MIME Types are currently
72     -- guessed only by file name. 
73     -- 
74     -- Guessing by file magic is indeed a wonderful idea but that is
75     -- not implemented (yet). But, don't you think it's better a file
76     -- system got a MIME Type as a part of inode? Or it might be a
77     -- good idea to use GnomeVFS
78     -- (<http://developer.gnome.org/doc/API/2.0/gnome-vfs-2.0/>)
79     -- instead of vanilla FS.
80     , cnfExtToMIMEType ∷ !ExtMap
81     }
82
83 -- |Configuration record for HTTPS connections.
84 data SSLConfig
85     = SSLConfig {
86         -- |A port ID to listen to HTTPS clients. Local addresses
87         -- (both for IPv4 and IPv6) will be derived from the parent
88         -- 'Config'.
89         sslServerPort ∷ !ServiceName
90
91         -- |An SSL context for accepting connections.
92       , sslContext    ∷ !SSLContext
93       }
94
95 -- |The default configuration. Generally you can use this value as-is,
96 -- or possibly you just want to replace the 'cnfServerSoftware' and
97 -- 'cnfServerPort'. SSL connections are disabled by default.
98 defaultConfig ∷ Config
99 defaultConfig = Config {
100                   cnfServerSoftware              = "Lucu/1.0"
101                 , cnfServerHost                  = T.pack (unsafePerformIO getHostName)
102                 , cnfServerPort                  = "http"
103                 , cnfServerV4Addr                = Just "0.0.0.0"
104                 , cnfServerV6Addr                = Just "::"
105                 , cnfSSLConfig                   = Nothing
106                 , cnfMaxPipelineDepth            = 100
107                 , cnfMaxEntityLength             = 16 * 1024 * 1024 -- 16 MiB
108                 , cnfDumpTooLateAbortionToStderr = True
109                 , cnfExtToMIMEType               = defaultExtensionMap
110                 }