on master help sign in
Spaces in HTTP version (#76)
a827f54Michael Snoyman
warp/Network/Wai/Handler/Warp.hs+4−3
@@ -488,9 +488,10 @@ takeUntil c bs =
488parseFirst :: ByteString
488parseFirst :: ByteString
489 -> ResourceT IO (ByteString, ByteString, ByteString, H.HttpVersion)
489 -> ResourceT IO (ByteString, ByteString, ByteString, H.HttpVersion)
490parseFirst s =
490parseFirst s =
491− case filter (not . S.null) $ S.split 32 s of -- ' '
491+ case filter (not . S.null) $ S.splitWith (\c -> c == 32 || c == 9) s of -- ' '
492− [method, query, http'] -> do
492+ (method:query:http'') -> do
493+ let http' = S.concat http''
493− let (hfirst, hsecond) = B.splitAt 5 http'
494+ (hfirst, hsecond) = B.splitAt 5 http'
494 if hfirst == "HTTP/"
495 if hfirst == "HTTP/"
495 then let (rpath, qstring) = S.breakByte 63 query -- '?'
496 then let (rpath, qstring) = S.breakByte 63 query -- '?'
496 hv =
497 hv =
warp/test/main.hs+18
@@ -208,6 +208,24 @@ main = hspecX $ do
208 headers @?=
208 headers @?=
209 [ ("foo", "bar")
209 [ ("foo", "bar")
210 ]
210 ]
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
211
229
212 describe "chunked bodies" $ do
230 describe "chunked bodies" $ do
213 it "works" $ do
231 it "works" $ do