@@ -1,7 +1,9 @@
2module Network.Wai.Handler.Warp.WithApplication (
2module Network.Wai.Handler.Warp.WithApplication (
3 withApplication,
3 withApplication,
4+ withApplicationSettings,
4 testWithApplication,
5 testWithApplication,
6+ testWithApplicationSettings,
5 openFreePort,
7 openFreePort,
6 withFreePort,
8 withFreePort,
@@ -21,13 +23,21 @@ import Network.Wai.Handler.Warp.Types
22-- @since 3.2.4
24-- @since 3.2.4
23withApplication :: IO Application -> (Port -> IO a) -> IO a
25withApplication :: IO Application -> (Port -> IO a) -> IO a
24−withApplication mkApp action = do
26+withApplication = withApplicationSettings defaultSettings
28+-- | 'withApplication' with given 'Settings'. This will ignore the port value
29+-- set by 'setPort' in 'Settings'.
32+withApplicationSettings :: Settings -> IO Application -> (Port -> IO a) -> IO a
33+withApplicationSettings settings' mkApp action = do
25 app <- mkApp
34 app <- mkApp
26 withFreePort $ \ (port, sock) -> do
35 withFreePort $ \ (port, sock) -> do
27 started <- mkWaiter
36 started <- mkWaiter
28 let settings =
37 let settings =
29− defaultSettings{
38+ settings' {
30− settingsBeforeMainLoop = notify started ()
39+ settingsBeforeMainLoop
40+ = notify started () >> settingsBeforeMainLoop settings'
32 result <- race
42 result <- race
33 (runSettingsSocket settings sock app)
43 (runSettingsSocket settings sock app)
@@ -50,7 +60,13 @@ withApplication mkApp action = do
51-- @since 3.2.4
61-- @since 3.2.4
52testWithApplication :: IO Application -> (Port -> IO a) -> IO a
62testWithApplication :: IO Application -> (Port -> IO a) -> IO a
53−testWithApplication mkApp action = do
63+testWithApplication = testWithApplicationSettings defaultSettings
65+-- | 'testWithApplication' with given 'Settings'.
68+testWithApplicationSettings :: Settings -> IO Application -> (Port -> IO a) -> IO a
69+testWithApplicationSettings settings mkApp action = do
54 callingThread <- myThreadId
70 callingThread <- myThreadId
55 app <- mkApp
71 app <- mkApp
56 let wrappedApp request respond =
72 let wrappedApp request respond =