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