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