on master help sign in
Merge pull request #531 from utdemir/master
9d4cb5fMichael Snoyman
warp/Network/Wai/Handler/Warp.hs+2
@@ -91,7 +91,9 @@ module Network.Wai.Handler.Warp (
91 , FileInfo(..)
91 , FileInfo(..)
92 , getFileInfo
92 , getFileInfo
93 , withApplication
93 , withApplication
94+ , withApplicationSettings
94 , testWithApplication
95 , testWithApplication
96+ , testWithApplicationSettings
95 , openFreePort
97 , openFreePort
96 -- * Version
98 -- * Version
97 , warpVersion
99 , warpVersion
warp/Network/Wai/Handler/Warp/WithApplication.hs+20−4
@@ -1,7 +1,9 @@
1
1
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,
7) where
9) where
@@ -21,13 +23,21 @@ import Network.Wai.Handler.Warp.Types
21--
23--
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
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
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'
31 }
41 }
32 result <- race
42 result <- race
33 (runSettingsSocket settings sock app)
43 (runSettingsSocket settings sock app)
@@ -50,7 +60,13 @@ withApplication mkApp action = do
50--
60--
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
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
54 callingThread <- myThreadId
70 callingThread <- myThreadId
55 app <- mkApp
71 app <- mkApp
56 let wrappedApp request respond =
72 let wrappedApp request respond =