@@ -17,6 +17,7 @@ import Foreign.ForeignPtr (withForeignPtr)
1717import Foreign.Ptr (Ptr, plusPtr, minusPtr, nullPtr)
1818import Foreign.Storable (peek)
1919import qualified Network.HTTP.Types as H
20+import qualified Network.HTTP.Types.URI as H
2021import Network.Wai.Handler.Warp.Types
2122import qualified Network.HTTP.Types.Header as HH
2223-- $setup
@@ -35,7 +36,7 @@ parseHeaderLines :: [ByteString]
3536parseHeaderLines [] = throwIO $ NotEnoughLines []
3637parseHeaderLines (firstLine:otherLines) = do
3738 (method, path', query, httpversion) <- parseRequestLine firstLine
38− let path = parsePath path'
39+ let path = H.extractPath path'
3940 hdr = map parseHeader otherLines
4041 return (method, path', path, query, httpversion, hdr)
4142
@@ -114,29 +115,6 @@ parseRequestLine requestLine@(PS fptr off len) = withForeignPtr fptr $ \ptr -> d
114115
115116----------------------------------------------------------------
116117
117−-- |
118−--
119−-- >>> parsePath ""
120−-- "/"
121−-- >>> parsePath "http://example.com:8080/path"
122−-- "/path"
123−-- >>> parsePath "http://example.com"
124−-- "/"
125−-- >>> parsePath "/path"
126−-- "/path"
127−
128−-- FIXME: parsePath "http://example.com" should be "/"?
129−parsePath :: ByteString -> ByteString
130−parsePath path
131− | "http://" `S.isPrefixOf` path = ensureNonEmpty $ extractPath path
132− | otherwise = ensureNonEmpty path
133− where
134− extractPath = snd . S.breakByte 47 . S.drop 7 -- 47 is '/'.
135− ensureNonEmpty "" = "/"
136− ensureNonEmpty p = p
137−
138−----------------------------------------------------------------
139−
140118-- |
141119--
142120-- >>> parseHeader "Content-Length:47"