@@ -12,7 +12,6 @@ import Control.Exception.Lifted (throwIO)
12import Control.Monad.IO.Class (liftIO)
12import Control.Monad.IO.Class (liftIO)
13import Data.ByteString (ByteString)
13import Data.ByteString (ByteString)
14import qualified Data.ByteString as S
14import qualified Data.ByteString as S
15−import qualified Data.ByteString.Char8 as B (unpack)
16import qualified Data.ByteString.Unsafe as SU
15import qualified Data.ByteString.Unsafe as SU
17import qualified Data.CaseInsensitive as CI
16import qualified Data.CaseInsensitive as CI
18import Data.Conduit
17import Data.Conduit
@@ -21,12 +20,13 @@ import Data.Monoid (mempty)
21import qualified Network.HTTP.Types as H
20import qualified Network.HTTP.Types as H
22import Network.Socket (SockAddr)
21import Network.Socket (SockAddr)
23import Network.Wai
22import Network.Wai
24−import Network.Wai.Internal
25import Network.Wai.Handler.Warp.Conduit
23import Network.Wai.Handler.Warp.Conduit
26import Network.Wai.Handler.Warp.ReadInt
24import Network.Wai.Handler.Warp.ReadInt
25+import Network.Wai.Handler.Warp.RequestHeader
26+import qualified Network.Wai.Handler.Warp.Timeout as Timeout
27import Network.Wai.Handler.Warp.Types
27import Network.Wai.Handler.Warp.Types
28+import Network.Wai.Internal
28import Prelude hiding (lines)
29import Prelude hiding (lines)
29−import qualified Network.Wai.Handler.Warp.Timeout as Timeout
31----------------------------------------------------------------
31----------------------------------------------------------------
@@ -70,51 +70,6 @@ headerLines =
71----------------------------------------------------------------
71----------------------------------------------------------------
73−parseHeaderLines :: [ByteString] -> IO (ByteString, ByteString, ByteString, H.HttpVersion, H.RequestHeaders)
74−parseHeaderLines [] = throwIO $ NotEnoughLines []
75−parseHeaderLines (firstLine:otherLines) = do
76− (method, rpath', gets, httpversion) <- parseFirst firstLine
77− let rpath = parseRpath rpath'
78− hdr = map parseHeaderNoAttr otherLines
79− return (method, rpath, gets, httpversion, hdr)
81−----------------------------------------------------------------
83−parseFirst :: ByteString
84− -> IO (ByteString, ByteString, ByteString, H.HttpVersion)
86− case filter (not . S.null) $ S.splitWith (\c -> c == 32 || c == 9) s of -- ' '
87− (method:query:http'') -> do
88− let http' = S.concat http''
89− (hfirst, hsecond) = S.splitAt 5 http'
91− then let (rpath, qstring) = S.breakByte 63 query -- '?'
96− in return (method, rpath, qstring, hv)
98− _ -> throwIO $ BadFirstLine $ B.unpack s
100−----------------------------------------------------------------
102−parseHeaderNoAttr :: ByteString -> H.Header
103−parseHeaderNoAttr s =
104− let (k, rest) = S.breakByte 58 s -- ':'
105− rest' = S.dropWhile (\c -> c == 32 || c == 9) $ S.drop 1 rest
108−----------------------------------------------------------------
110−parseRpath :: ByteString -> ByteString
112− | S.null rpath' = "/"
113− | "http://" `S.isPrefixOf` rpath' = snd $ S.breakByte 47 $ S.drop 7 rpath'
114− | otherwise = rpath'
116−----------------------------------------------------------------
118handleExpect :: Connection
73handleExpect :: Connection
119 -> H.HttpVersion
74 -> H.HttpVersion
120 -> (H.RequestHeaders -> H.RequestHeaders)
75 -> (H.RequestHeaders -> H.RequestHeaders)
@@ -199,7 +154,7 @@ push (THStatus len lines prepend) bs
199 0 -> True
154 0 -> True
200 1 -> S.index bs 0 == 13
155 1 -> S.index bs 0 == 13
201 _ -> False
156 _ -> False
202− in Just (nl, (not b) && (c == 32 || c == 9))
157+ in Just (nl, not b && (c == 32 || c == 9))
204 Just (nl, False)
159 Just (nl, False)