on master help sign in
WAI 0.3
commitd77c9500773bd2ad526679aca122e5974cfe699e authorMichael Snoyman <michael@snoyman.com> dateThu 30 Dec 2010, 07:06 (16 years ago) parentbd17d89
2 files changed+19−11
Network/Wai/Handler/DevelServer.hs+16−8 wai-handler-devel.cabal+3−3
Network/Wai/Handler/DevelServer.hs+16−8
@@ -21,7 +21,7 @@ import Control.Concurrent (forkIO, threadDelay)
2121import qualified Control.Concurrent.MVar as M
2222import qualified Control.Concurrent.Chan as C
2323import System.Directory (getModificationTime)
24−import Network.Wai.Handler.SimpleServer (parseRequest, sendResponse)
24+import Network.Wai.Handler.Warp (parseRequest, sendResponse, drainRequestBody)
2525import Control.Monad (filterM)
2626
2727import Control.Arrow ((&&&))
@@ -62,8 +62,10 @@ startApp queue withApp = do
6262 go app
6363 onErr :: SomeException -> IO Response
6464 onErr e = return
65− $ Response status500 [("Content-Type", "text/plain; charset=utf-8")]
66− $ ResponseLBS $ encodeUtf8 $ pack
65+ $ responseLBS
66+ status500
67+ [("Content-Type", "text/plain; charset=utf-8")]
68+ $ charsToLBS
6769 $ "Exception thrown while running application\n\n" ++ show e
6870 void x = x >> return ()
6971
@@ -155,15 +157,18 @@ swapApp app mqueue = do
155157
156158loadingApp :: Maybe SomeException -> Handler
157159loadingApp err f =
158− f $ const $ return $ Response status200
160+ f $ const $ return $ responseLBS status200
159161 ( ("Content-Type", "text/plain")
160162 : case err of
161163 Nothing -> [("Refresh", "1")]
162164 Just _ -> []
163− ) $ ResponseLBS $ L8.pack $ toMessage err
165+ ) $ toMessage err
164166 where
165167 toMessage Nothing = "Loading code changes, please wait"
166− toMessage (Just err') = "Error loading code: " ++ show err'
168+ toMessage (Just err') = charsToLBS $ "Error loading code: " ++ show err'
169+
170+charsToLBS :: String -> L8.ByteString
171+charsToLBS = encodeUtf8 . pack
167172
168173type Handler = (Application -> IO ()) -> IO ()
169174
@@ -198,10 +203,13 @@ type Queue = C.Chan (Maybe (Request, Response -> IO ()))
198203
199204serveConnection :: Port -> M.MVar Queue -> Handle -> String -> IO ()
200205serveConnection port mqueue conn remoteHost' = do
201− env <- parseRequest port conn remoteHost'
206+ (ilen, env) <- parseRequest port conn remoteHost'
202207 let onRes res =
203208 finally
204− (sendResponse (httpVersion env) conn res)
209+ (do
210+ _ <- sendResponse env (httpVersion env) conn res
211+ drainRequestBody conn ilen
212+ return ())
205213 (hClose conn)
206214 queue <- M.readMVar mqueue
207215 C.writeChan queue $ Just (env, onRes)
wai-handler-devel.cabal+3−3
@@ -1,5 +1,5 @@
11Name: wai-handler-devel
2−Version: 0.1.1.2
2+Version: 0.2.0
33Synopsis: WAI server that automatically reloads code after modification.
44Description: This handler automatically reloads your source code upon any changes. It works by using the hint package, essentially embedding GHC inside the handler. The handler (both the executable and library) takes three arguments: the port to listen on, the module name containing the application function, and the name of the function.
55 .
@@ -22,8 +22,8 @@ Source-repository head
2222
2323Library
2424 Build-Depends: base >= 4 && < 5
25− , wai >= 0.2.1 && < 0.3
26− , wai-extra >= 0.2.3 && < 0.3
25+ , wai >= 0.3 && < 0.4
26+ , warp >= 0.3 && < 0.4
2727 , directory >= 1.0 && < 1.2
2828 , network >= 2.2 && < 2.4
2929 , bytestring >= 0.9 && < 0.10