@@ -26,6 +26,7 @@ module Network.Wai.Handler.Warp (
2626 , Settings
2727 , defaultSettings
2828 -- ** Accessors
29+ -- | Note: these accessors are deprecated, please use the @set@ versions instead.
2930 , settingsPort
3031 , settingsHost
3132 , settingsOnException
@@ -90,16 +91,97 @@ import Network.Wai.Handler.Warp.Run
9091import Network.Wai.Handler.Warp.Settings
9192import Network.Wai.Handler.Warp.Timeout
9293import Network.Wai.Handler.Warp.Types
94+import Control.Exception (SomeException)
95+import Network.Wai (Request, Response)
96+import Network.Socket (SockAddr)
97+import Data.Conduit (Source)
98+import Data.ByteString (ByteString)
9399
100+-- | Port to listen on. Default value: 3000
101+--
102+-- Since 2.1.0
103+setPort :: Int -> Settings -> Settings
94104setPort x y = y { settingsPort = x }
105+
106+-- | Interface to bind to. Default value: HostIPv4
107+--
108+-- Since 2.1.0
109+setHost :: HostPreference -> Settings -> Settings
95110setHost x y = y { settingsHost = x }
111+
112+-- | What to do with exceptions thrown by either the application or server.
113+-- Default: ignore server-generated exceptions (see 'InvalidRequest') and print
114+-- application-generated applications to stderr.
115+--
116+-- Since 2.1.0
117+setOnException :: (Maybe Request -> SomeException -> IO ()) -> Settings -> Settings
96118setOnException x y = y { settingsOnException = x }
119+
120+-- | A function to create `Response` when an exception occurs.
121+--
122+-- Default: 500, text/plain, \"Something went wrong\"
123+--
124+-- Since 2.1.0
125+setOnExceptionResponse :: (SomeException -> Response) -> Settings -> Settings
97126setOnExceptionResponse x y = y { settingsOnExceptionResponse = x }
127+
128+-- | What to do when a connection is open. When 'False' is returned, the
129+-- connection is closed immediately. Otherwise, the connection is going on.
130+-- Default: always returns 'True'.
131+--
132+-- Since 2.1.0
133+setOnOpen :: (SockAddr -> IO Bool) -> Settings -> Settings
98134setOnOpen x y = y { settingsOnOpen = x }
135+
136+-- | What to do when a connection is close. Default: do nothing.
137+--
138+-- Since 2.1.0
139+setOnClose :: (SockAddr -> IO ()) -> Settings -> Settings
99140setOnClose x y = y { settingsOnClose = x }
141+
142+-- | Timeout value in seconds. Default value: 30
143+--
144+-- Since 2.1.0
145+setTimeout :: Int -> Settings -> Settings
100146setTimeout x y = y { settingsTimeout = x }
147+
148+-- | Register some intercept handler to deal with specific requests. Prime use
149+-- case: websockets.
150+--
151+-- Default: always return @Nothing@.
152+--
153+-- Since 2.1.0
154+setIntercept :: (Request -> IO (Maybe (Source IO ByteString -> Connection -> IO ())))
155+ -> Settings -> Settings
101156setIntercept x y = y { settingsIntercept = x }
102−setManager x y = y { settingsManager = x }
157+
158+-- | Use an existing timeout manager instead of spawning a new one. If used,
159+-- 'settingsTimeout' is ignored.
160+--
161+-- Since 2.1.0
162+setManager :: Manager -> Settings -> Settings
163+setManager x y = y { settingsManager = Just x }
164+
165+-- | Cache duratoin time of file descriptors in seconds. 0 means that the cache mechanism is not used. Default value: 10
166+setFdCacheDuration :: Int -> Settings -> Settings
103167setFdCacheDuration x y = y { settingsFdCacheDuration = x }
168+
169+-- | Code to run after the listening socket is ready but before entering
170+-- the main event loop. Useful for signaling to tests that they can start
171+-- running, or to drop permissions after binding to a restricted port.
172+--
173+-- Default: do nothing.
174+--
175+-- Since 2.1.0
176+setBeforeMainLoop :: IO () -> Settings -> Settings
104177setBeforeMainLoop x y = y { settingsBeforeMainLoop = x }
178+
179+-- | Perform no parsing on the rawPathInfo.
180+--
181+-- This is useful for writing HTTP proxies.
182+--
183+-- Default: False
184+--
185+-- Since 2.1.0
186+setNoParsePath :: Bool -> Settings -> Settings
105187setNoParsePath x y = y { settingsNoParsePath = x }