5 -- |Configurations for the Lucu httpd.
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 to run the httpd.
23 data Config = Config {
25 -- |A banner string to be sent to clients with \"Server\" response
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 a 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 ways to assign separate ports to
45 -- IPv4 and IPv6 server sockets (but I don't think that will be a
47 , cnfServerV6Addr ∷ !(Maybe HostName)
49 -- |Configuration for HTTPS connections. Set this 'Nothing' to
51 , cnfSSLConfig ∷ !(Maybe SSLConfig)
53 -- |The maximum number of requests to simultaneously accept in one
54 -- connection. If a client exceeds this limitation, its last
55 -- request won't be processed until a response for its earliest
56 -- pending request is sent back to the client.
57 , cnfMaxPipelineDepth ∷ !Int
59 -- |The maximum length of request entity to accept in octets. Note
60 -- that this is nothing but a default value used by
61 -- 'Network.HTTP.Lucu.Resource.getForm' and such when they are
62 -- applied to 'Network.HTTP.Lucu.Resource.defaultLimit', so there
63 -- is no guarantee that this value always constrains all the
65 , cnfMaxEntityLength ∷ !Int
67 -- |Whether to dump too late abortions to the stderr or not. See
68 -- 'Network.HTTP.Lucu.Abortion.abort'.
69 , cnfDumpTooLateAbortionToStderr ∷ !Bool
71 -- |A mapping table from file extensions to MIME Types. This value
72 -- is used by 'Network.HTTP.Lucu.StaticFile.staticFile' to guess
73 -- the MIME Type of static files. Note that MIME Types are
74 -- currently guessed only by file name.
76 -- Guessing by file magic might be a good idea but that's not
78 , cnfExtToMIMEType ∷ !ExtMap
81 -- |Configuration record for HTTPS connections.
84 -- |A port number (or a service name) to listen to HTTPS
85 -- clients. Local addresses (both for IPv4 and IPv6) will be
86 -- derived from the parent 'Config'.
87 sslServerPort ∷ !ServiceName
89 -- |An SSL context for accepting connections. You must set it
90 -- up yourself with at least a server certification.
91 , sslContext ∷ !SSLContext
94 -- |The default configuration. Generally you can use this value as-is,
95 -- or possibly you just want to replace the 'cnfServerSoftware' and
96 -- 'cnfServerPort'. SSL connections are disabled by default.
97 defaultConfig ∷ Config
98 defaultConfig = Config {
99 cnfServerSoftware = "Lucu/1.0"
100 , cnfServerHost = T.pack (unsafePerformIO getHostName)
101 , cnfServerPort = "http"
102 , cnfServerV4Addr = Just "0.0.0.0"
103 , cnfServerV6Addr = Just "::"
104 , cnfSSLConfig = Nothing
105 , cnfMaxPipelineDepth = 100
106 , cnfMaxEntityLength = 16 * 1024 * 1024 -- 16 MiB
107 , cnfDumpTooLateAbortionToStderr = True
108 , cnfExtToMIMEType = defaultExtensionMap