on master help sign in
adding doctests.
commit839a757904b1f63641b1b816aa028a48e61c91fa authorKazu Yamamoto <kazu@iij.ad.jp> dateFri 1 Nov 2013, 13:39 (13 years ago) parentc8a8f8c
2 files changed+26−4
warp/Network/Wai/Handler/Warp/RequestHeader.hs+18−4 warp/warp.cabal+8
warp/Network/Wai/Handler/Warp/RequestHeader.hs+18−4
@@ -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 -- ':'
warp/warp.cabal+8
@@ -79,6 +79,14 @@ Library
7979 else
8080 Build-Depends: unix
8181
82+Test-Suite doctest
83+ Type: exitcode-stdio-1.0
84+ HS-Source-Dirs: test
85+ Ghc-Options: -threaded -Wall
86+ Main-Is: doctests.hs
87+ Build-Depends: base
88+ , doctest >= 0.9.3
89+
8290Test-Suite spec
8391 Main-Is: Spec.hs
8492 Other-modules: ConduitSpec