@@ -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,27 +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−parsePath :: ByteString -> ByteString
128−parsePath path
129− | "http://" `S.isPrefixOf` path = ensureNonEmpty $ extractPath path
130− | otherwise = ensureNonEmpty path
131− where
132− extractPath = snd . S.breakByte 47 . S.drop 7 -- 47 is '/'.
133− ensureNonEmpty "" = "/"
134− ensureNonEmpty p = p
135−
136−----------------------------------------------------------------
137−
138118-- |
139119--
140120-- >>> parseHeader "Content-Length:47"