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 -- |The maximum length of chunk to output. This value is used by
66 -- 'Network.HTTP.Lucu.Resource.output' and such like to limit the
67 -- chunk length so you can safely output an infinite string (like
68 -- a lazy stream of \/dev\/random) using those actions.
69 , cnfMaxOutputChunkLength ∷ !Int
71 -- | Whether to dump too late abortion to the stderr or not. See
72 -- 'Network.HTTP.Lucu.Abortion.abort'.
73 , cnfDumpTooLateAbortionToStderr ∷ !Bool
75 -- |A mapping from extension to MIME Type. This value is used by
76 -- 'Network.HTTP.Lucu.StaticFile.staticFile' to guess the MIME
77 -- Type of static files. Note that MIME Types are currently
78 -- guessed only by file name.
80 -- Guessing by file magic is indeed a wonderful idea but that is
81 -- not implemented (yet). But, don't you think it's better a file
82 -- system got a MIME Type as a part of inode? Or it might be a
83 -- good idea to use GnomeVFS
84 -- (<http://developer.gnome.org/doc/API/2.0/gnome-vfs-2.0/>)
85 -- instead of vanilla FS.
86 , cnfExtToMIMEType ∷ !ExtMap
89 -- |Configuration record for HTTPS connections.
92 -- |A port ID to listen to HTTPS clients. Local addresses
93 -- (both for IPv4 and IPv6) will be derived from the parent
95 sslServerPort ∷ !ServiceName
97 -- |An SSL context for accepting connections.
98 , sslContext ∷ !SSLContext
101 -- |The default configuration. Generally you can use this value as-is,
102 -- or possibly you just want to replace the 'cnfServerSoftware' and
103 -- 'cnfServerPort'. SSL connections are disabled by default.
104 defaultConfig ∷ Config
105 defaultConfig = Config {
106 cnfServerSoftware = "Lucu/1.0"
107 , cnfServerHost = T.pack (unsafePerformIO getHostName)
108 , cnfServerPort = "http"
109 , cnfServerV4Addr = Just "0.0.0.0"
110 , cnfServerV6Addr = Just "::"
111 , cnfSSLConfig = Nothing
112 , cnfMaxPipelineDepth = 100
113 , cnfMaxEntityLength = 16 * 1024 * 1024 -- 16 MiB
114 , cnfMaxOutputChunkLength = 5 * 1024 * 1024 -- 5 MiB
115 , cnfDumpTooLateAbortionToStderr = True
116 , cnfExtToMIMEType = defaultExtensionMap