@@ -11,6 +11,9 @@ import qualified Network.HTTP.Types as H
1111import Network.Wai.Handler.Warp.Types
1212import Prelude hiding (lines)
1313
14+-- $setup
15+-- >>> :set -XOverloadedStrings
16+
1417----------------------------------------------------------------
1518
1619parseHeaderLines :: [ByteString]
@@ -49,13 +52,24 @@ parseRequestLine s =
4952----------------------------------------------------------------
5053
5154parseRpath :: ByteString -> ByteString
52−parseRpath rpath'
53− | S.null rpath' = "/"
54− | "http://" `S.isPrefixOf` rpath' = snd $ S.breakByte 47 $ S.drop 7 rpath'
55− | otherwise = rpath'
55+parseRpath path
56+ | S.null path = "/"
57+ | "http://" `S.isPrefixOf` path = extractPath path
58+ | otherwise = path
59+ where
60+ extractPath = snd . S.breakByte 47 . S.drop 7 -- 47 is '/'.
5661
5762----------------------------------------------------------------
5863
64+-- |
65+--
66+-- >>> parseHeader "Content-Length:47"
67+-- ("Content-Length","47")
68+-- >>> parseHeader "Accept-Ranges: bytes"
69+-- ("Accept-Ranges","bytes")
70+-- >>> parseHeader "Host: example.com:8080"
71+-- ("Host","example.com:8080")
72+
5973parseHeader :: ByteString -> H.Header
6074parseHeader s =
6175 let (k, rest) = S.breakByte 58 s -- ':'