1 -- |Configurations for the Lucu httpd like a port to listen.
2 module Network.HTTP.Lucu.Config
9 import qualified Data.ByteString as Strict (ByteString)
10 import qualified Data.ByteString.Char8 as C8 hiding (ByteString)
13 import Network.HTTP.Lucu.MIMEType.Guess
14 import Network.HTTP.Lucu.MIMEType.DefaultExtensionMap
15 import OpenSSL.Session
16 import System.IO.Unsafe
18 -- |Configuration record for the Lucu httpd. You need to use
19 -- 'defaultConfig' or setup your own configuration to run the httpd.
20 data Config = Config {
22 -- |A string which will be sent to clients as \"Server\" field.
23 cnfServerSoftware :: !Strict.ByteString
25 -- |The host name of the server. This value will be used in
26 -- built-in pages like \"404 Not Found\".
27 , cnfServerHost :: !Strict.ByteString
29 -- |A port number (or service name) to listen to HTTP clients.
30 , cnfServerPort :: !ServiceName
32 -- |Local IPv4 address to listen to both HTTP and HTTPS
33 -- clients. Set this to @('Just' "0.0.0.0")@ if you want to accept
34 -- any IPv4 connections. Set this to 'Nothing' to disable IPv4.
35 , cnfServerV4Addr :: !(Maybe HostName)
37 -- |Local IPv6 address to listen to both HTTP and HTTPS
38 -- clients. Set this to @('Just' "::")@ if you want to accept any
39 -- IPv6 connections. Set this to 'Nothing' to disable IPv6. Note
40 -- that there is currently no way to assign separate ports to IPv4
41 -- and IPv6 server sockets.
42 , cnfServerV6Addr :: !(Maybe HostName)
44 -- |Configuration for HTTPS connections. Set this 'Nothing' to
46 , cnfSSLConfig :: !(Maybe SSLConfig)
48 -- |The maximum number of requests to accept in one connection
49 -- simultaneously. If a client exceeds this limitation, its last
50 -- request won't be processed until a response for its earliest
51 -- pending request is sent back to the client.
52 , cnfMaxPipelineDepth :: !Int
54 -- |The maximum length of request entity to accept in bytes. Note
55 -- that this is nothing but the default value which is used when
56 -- 'Network.HTTP.Lucu.Resource.input' and such like are applied to
57 -- 'Network.HTTP.Lucu.Resource.defaultLimit', so there is no
58 -- guarantee that this value always constrains all the requests.
59 , cnfMaxEntityLength :: !Int
61 -- |The maximum length of chunk to output. This value is used by
62 -- 'Network.HTTP.Lucu.Resource.output' and such like to limit the
63 -- chunk length so you can safely output an infinite string (like
64 -- a lazy stream of \/dev\/random) using those actions.
65 , cnfMaxOutputChunkLength :: !Int
67 -- | Whether to dump too late abortion to the stderr or not. See
68 -- 'Network.HTTP.Lucu.Abortion.abort'.
69 , cnfDumpTooLateAbortionToStderr :: !Bool
71 -- |A mapping from extension to MIME Type. This value is used by
72 -- 'Network.HTTP.Lucu.StaticFile.staticFile' to guess the MIME
73 -- Type of static files. Note that MIME Types are currently
74 -- guessed only by file name.
76 -- Guessing by file magic is indeed a wonderful idea but that is
77 -- not implemented (yet). But, don't you think it's better a file
78 -- system got a MIME Type as a part of inode? Or it might be a
79 -- good idea to use GnomeVFS
80 -- (<http://developer.gnome.org/doc/API/2.0/gnome-vfs-2.0/>)
81 -- instead of vanilla FS.
82 , cnfExtToMIMEType :: !ExtMap
85 -- |Configuration record for HTTPS connections.
88 -- |A port ID to listen to HTTPS clients. Local addresses
89 -- (both for IPv4 and IPv6) will be derived from the parent
91 sslServerPort :: !ServiceName
93 -- |An SSL context for accepting connections.
94 , sslContext :: !SSLContext
97 -- |The default configuration. Generally you can use this value as-is,
98 -- or possibly you just want to replace the 'cnfServerSoftware' and
99 -- 'cnfServerPort'. SSL connections are disabled by default.
100 defaultConfig :: Config
101 defaultConfig = Config {
102 cnfServerSoftware = C8.pack "Lucu/1.0"
103 , cnfServerHost = C8.pack (unsafePerformIO getHostName)
104 , cnfServerPort = "http"
105 , cnfServerV4Addr = Just "0.0.0.0"
106 , cnfServerV6Addr = Just "::"
107 , cnfSSLConfig = Nothing
108 , cnfMaxPipelineDepth = 100
109 , cnfMaxEntityLength = 16 * 1024 * 1024 -- 16 MiB
110 , cnfMaxOutputChunkLength = 5 * 1024 * 1024 -- 5 MiB
111 , cnfDumpTooLateAbortionToStderr = True
112 , cnfExtToMIMEType = defaultExtensionMap