on master help sign in
warp: Use extractPath from http-types-0.8.5
commit9fd40c7e7081d231d464eaa7c5d90171259f5c16 authorSimon Hengel <sol@typeful.net> dateFri 23 May 2014, 15:11 (12 years ago) parentd3a969b
2 files changed+3−23
warp/Network/Wai/Handler/Warp/RequestHeader.hs+2−22 warp/warp.cabal+1−1
warp/Network/Wai/Handler/Warp/RequestHeader.hs+2−22
@@ -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"
warp/warp.cabal+1−1
@@ -45,7 +45,7 @@ Library
4545 , conduit >= 0.5 && < 1.2
4646 , conduit-extra
4747 , ghc-prim
48− , http-types >= 0.7
48+ , http-types >= 0.8.5
4949 , lifted-base >= 0.1
5050 , network-conduit >= 0.5 && < 1.2
5151 , simple-sendfile >= 0.2.7 && < 0.3