on master help sign in
Merge pull request #531 from utdemir/master

Add {test,}withApplicationSettings

commit9d4cb5f21996996aa1788c8a03a51dbb4e92be10 authorMichael Snoyman <michael@snoyman.com> dateWed 13 Apr 2016, 08:11 (11 years ago) parentf7895503c48bad
2 files changed+22−4
warp/Network/Wai/Handler/Warp.hs+2 warp/Network/Wai/Handler/Warp/WithApplication.hs+20−4
warp/Network/Wai/Handler/Warp.hs+2
@@ -91,7 +91,9 @@ module Network.Wai.Handler.Warp (
9191 , FileInfo(..)
9292 , getFileInfo
9393 , withApplication
94+ , withApplicationSettings
9495 , testWithApplication
96+ , testWithApplicationSettings
9597 , openFreePort
9698 -- * Version
9799 , warpVersion
warp/Network/Wai/Handler/Warp/WithApplication.hs+20−4
@@ -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 =