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