5 -- |Configurations for the Lucu httpd like a port to listen.
6 module Network.HTTP.Lucu.Config
12 import Data.Ascii (Ascii)
13 import Data.Text (Text)
14 import qualified Data.Text as T
17 import Network.HTTP.Lucu.MIMEType.Guess
18 import Network.HTTP.Lucu.MIMEType.DefaultExtensionMap
19 import OpenSSL.Session
20 import System.IO.Unsafe
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 {
26 -- |A string which will be sent to clients as \"Server\" field.
27 cnfServerSoftware ∷ !Ascii
29 -- |The host name of the server. This value will be used in
30 -- built-in pages like \"404 Not Found\".
31 , cnfServerHost ∷ !Text
33 -- |A port number (or service name) to listen to HTTP clients.
34 , cnfServerPort ∷ !ServiceName
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)
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)
48 -- |Configuration for HTTPS connections. Set this 'Nothing' to
50 , cnfSSLConfig ∷ !(Maybe SSLConfig)
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
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
65 -- | Whether to dump too late abortion to the stderr or not. See
66 -- 'Network.HTTP.Lucu.Abortion.abort'.
67 , cnfDumpTooLateAbortionToStderr ∷ !Bool
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.
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
83 -- |Configuration record for HTTPS connections.
86 -- |A port ID to listen to HTTPS clients. Local addresses
87 -- (both for IPv4 and IPv6) will be derived from the parent
89 sslServerPort ∷ !ServiceName
91 -- |An SSL context for accepting connections.
92 , sslContext ∷ !SSLContext
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