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