on master help sign in
Spaces in HTTP version (#76)
commita827f54ac31e2c928144bb8bb5b92ca1249013c5 authorMichael Snoyman <michael@snoyman.com> dateThu 31 May 2012, 12:33 (14 years ago) parent9f8a458
2 files changed+22−3
warp/Network/Wai/Handler/Warp.hs+4−3 warp/test/main.hs+18
warp/Network/Wai/Handler/Warp.hs+4−3
@@ -488,9 +488,10 @@ takeUntil c bs =
488488parseFirst :: ByteString
489489 -> ResourceT IO (ByteString, ByteString, ByteString, H.HttpVersion)
490490parseFirst s =
491− case filter (not . S.null) $ S.split 32 s of -- ' '
492− [method, query, http'] -> do
493− let (hfirst, hsecond) = B.splitAt 5 http'
491+ case filter (not . S.null) $ S.splitWith (\c -> c == 32 || c == 9) s of -- ' '
492+ (method:query:http'') -> do
493+ let http' = S.concat http''
494+ (hfirst, hsecond) = B.splitAt 5 http'
494495 if hfirst == "HTTP/"
495496 then let (rpath, qstring) = S.breakByte 63 query -- '?'
496497 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