@@ -1,7 +1,9 @@
11
22module Network.Wai.Handler.Warp.WithApplication (
33 withApplication,
4+ withApplicationSettings,
45 testWithApplication,
6+ testWithApplicationSettings,
57 openFreePort,
68 withFreePort,
79) where
@@ -21,13 +23,21 @@ import Network.Wai.Handler.Warp.Types
2123--
2224-- @since 3.2.4
2325withApplication :: IO Application -> (Port -> IO a) -> IO a
24−withApplication mkApp action = do
26+withApplication = withApplicationSettings defaultSettings
27+
28+-- | 'withApplication' with given 'Settings'. This will ignore the port value
29+-- set by 'setPort' in 'Settings'.
30+--
31+-- @since 3.2.7
32+withApplicationSettings :: Settings -> IO Application -> (Port -> IO a) -> IO a
33+withApplicationSettings settings' mkApp action = do
2534 app <- mkApp
2635 withFreePort $ \ (port, sock) -> do
2736 started <- mkWaiter
2837 let settings =
29− defaultSettings{
30− settingsBeforeMainLoop = notify started ()
38+ settings' {
39+ settingsBeforeMainLoop
40+ = notify started () >> settingsBeforeMainLoop settings'
3141 }
3242 result <- race
3343 (runSettingsSocket settings sock app)
@@ -50,7 +60,13 @@ withApplication mkApp action = do
5060--
5161-- @since 3.2.4
5262testWithApplication :: IO Application -> (Port -> IO a) -> IO a
53−testWithApplication mkApp action = do
63+testWithApplication = testWithApplicationSettings defaultSettings
64+
65+-- | 'testWithApplication' with given 'Settings'.
66+--
67+-- @since 3.2.7
68+testWithApplicationSettings :: Settings -> IO Application -> (Port -> IO a) -> IO a
69+testWithApplicationSettings settings mkApp action = do
5470 callingThread <- myThreadId
5571 app <- mkApp
5672 let wrappedApp request respond =