on master help sign in
Merge branch 'master' into beta

Conflicts: wai-app-static/Network/Wai/Application/Static.hs warp/Network/Wai/Handler/Warp.hs warp/test/main.hs

commitc5698da79448ffb7fda4f1877b74c0d87f473c4f authorMichael Snoyman <michael@snoyman.com> dateMon 11 Jun 2012, 09:25 (14 years ago) parent71ce33f810d0a4
5 files changed+29−7
wai-eventsource/src/Network/Wai/EventSource.hs+4−1 wai-handler-devel/Network/Wai/Handler/DevelServer.hs+1−1 wai/Network/Wai.hs+2−2 warp/Network/Wai/Handler/Warp.hs+4−3 warp/test/main.hs+18
wai-eventsource/src/Network/Wai/EventSource.hs+4−1
@@ -3,7 +3,8 @@ module Network.Wai.EventSource (
33 ServerEvent(..),
44 eventSourceAppChan,
55 eventSourceAppSource,
6− eventSourceAppIO
6+ eventSourceAppIO,
7+ sourceToSource
78 ) where
89
910import Blaze.ByteString.Builder (Builder)
@@ -59,6 +60,8 @@ ioToSource act =
5960 Just y -> C.StateOpen (Just C.Flush) (C.Chunk y)
6061 pull (Just x) = return $ C.StateOpen Nothing x
6162
63+-- | Convert a ServerEvent source into a Builder source of serialized
64+-- events.
6265sourceToSource :: Monad m => C.Source m ServerEvent -> C.Source m (C.Flush Builder)
6366sourceToSource src = src $= CL.concatMap eventToFlushBuilder
6467 where
wai-handler-devel/Network/Wai/Handler/DevelServer.hs+1−1
@@ -190,7 +190,7 @@ theapp modu func =
190190 runInterpreter $ do
191191 loadModules [modu]
192192 mods <- getLoadedModules
193− setImports ["Prelude", "Network.Wai", "Data.Enumerator", "Data.ByteString.Internal", modu]
193+ setImports ["Prelude", "Network.Wai", "Data.Enumerator", "Data.ByteString.Internal", "Control.Monad.Trans.Resource", modu]
194194 app <- interpret func infer
195195 return (app, map toFile mods)
196196 where
wai/Network/Wai.hs+2−2
@@ -7,8 +7,8 @@ This module defines a generic web application interface. It is a common
77protocol between web servers and web applications.
88
99The overriding design principles here are performance and generality . To
10−address performance, this library is built on top of the enumerator and
11−blaze-builder packages. The advantages of enumerators over lazy IO have been
10+address performance, this library is built on top of the conduit and
11+blaze-builder packages. The advantages of conduits over lazy IO have been
1212debated elsewhere and so will not be addressed here. However, helper functions
1313like 'responseLBS' allow you to continue using lazy IO if you so desire.
1414
warp/Network/Wai/Handler/Warp.hs+4−3
@@ -486,9 +486,10 @@ takeUntil c bs =
486486parseFirst :: ByteString
487487 -> ResourceT IO (ByteString, ByteString, ByteString, H.HttpVersion)
488488parseFirst s =
489− case filter (not . S.null) $ S.split 32 s of -- ' '
490− [method, query, http'] -> do
491− let (hfirst, hsecond) = B.splitAt 5 http'
489+ case filter (not . S.null) $ S.splitWith (\c -> c == 32 || c == 9) s of -- ' '
490+ (method:query:http'') -> do
491+ let http' = S.concat http''
492+ (hfirst, hsecond) = B.splitAt 5 http'
492493 if hfirst == "HTTP/"
493494 then let (rpath, qstring) = S.breakByte 63 query -- '?'
494495 hv =
warp/test/main.hs+18
@@ -208,6 +208,24 @@ main = hspecX $ do
208208 headers @?=
209209 [ ("foo", "bar")
210210 ]
211+ it "spaces in http version" $ do
212+ iversion <- I.newIORef $ error "Version not parsed"
213+ port <- getPort
214+ tid <- forkIO $ run port $ \req -> do
215+ liftIO $ I.writeIORef iversion $ httpVersion req
216+ return $ responseLBS status200 [] ""
217+ threadDelay 1000
218+ handle <- connectTo "127.0.0.1" $ PortNumber $ fromIntegral port
219+ let input = S.concat
220+ [ "GET / HTTP\t/ 1 . 1 \r\nfoo: bar\r\n\r\n"
221+ ]
222+ hPutStr handle input
223+ hFlush handle
224+ hClose handle
225+ threadDelay 1000
226+ killThread tid
227+ version <- I.readIORef iversion
228+ version @?= http11
211229
212230 describe "chunked bodies" $ do
213231 it "works" $ do