on master help sign in
avoiding ByteString.Char8.
commit9da7e283337ba76a1fa4edd9c9c41fd684bcb726 authorKazu Yamamoto <kazu@iij.ad.jp> dateFri 17 Aug 2012, 14:41 (14 years ago) parent6d2bcab
4 files changed+20−17
warp/Network/Wai/Handler/Warp/Conduit.hs+7−4 warp/Network/Wai/Handler/Warp/Request.hs+5−5 warp/Network/Wai/Handler/Warp/Response.hs+5−4 warp/Network/Wai/Handler/Warp/Types.hs+3−4
warp/Network/Wai/Handler/Warp/Conduit.hs+7−4
@@ -7,14 +7,12 @@ import Control.Monad.IO.Class (MonadIO, liftIO)
77import Control.Monad.Trans.Class (lift)
88import Data.ByteString (ByteString)
99import qualified Data.ByteString as S
10−import qualified Data.ByteString.Char8 as B
11−import Data.Char (isHexDigit)
1210import Data.Conduit
1311import qualified Data.Conduit.Binary as CB
1412import Data.Conduit.Internal (ResumableSource (..))
1513import qualified Data.Conduit.List as CL
1614import qualified Data.IORef as I
17−import Data.Word (Word)
15+import Data.Word (Word, Word8)
1816import Network.Wai.Handler.Warp.Types
1917
2018----------------------------------------------------------------
@@ -133,7 +131,7 @@ chunkedSource ipair = do
133131 | otherwise -> return (x, y)
134132 let w =
135133 S.foldl' (\i c -> i * 16 + fromIntegral (hexToWord c)) 0
136− $ B.takeWhile isHexDigit x
134+ $ S.takeWhile isHexDigit x
137135 return (w, S.drop 1 y)
138136
139137 hexToWord w
@@ -141,6 +139,11 @@ chunkedSource ipair = do
141139 | w < 71 = w - 55
142140 | otherwise = w - 87
143141
142+isHexDigit :: Word8 -> Bool
143+isHexDigit w = w >= 48 && w <= 57
144+ || w >= 65 && w <= 70
145+ || w >= 97 && w <= 102
146+
144147----------------------------------------------------------------
145148
146149fmapResume :: (Source m o1 -> Source m o2) -> ResumableSource m o1 -> ResumableSource m o2
warp/Network/Wai/Handler/Warp/Request.hs+5−5
@@ -8,7 +8,7 @@ import Control.Exception.Lifted (throwIO)
88import Control.Monad.IO.Class (MonadIO, liftIO)
99import Data.ByteString (ByteString)
1010import qualified Data.ByteString as S
11−import qualified Data.ByteString.Char8 as B
11+import qualified Data.ByteString.Char8 as B (unpack)
1212import qualified Data.ByteString.Unsafe as SU
1313import qualified Data.CaseInsensitive as CI
1414import Data.Conduit
@@ -30,7 +30,7 @@ maxTotalHeaderLength :: Int
3030maxTotalHeaderLength = 50 * 1024
3131
3232parseRequest :: Connection -> Port -> SockAddr
33− -> Source (ResourceT IO) S.ByteString
33+ -> Source (ResourceT IO) ByteString
3434 -> ResourceT IO (Request, IO (ResumableSource (ResourceT IO) ByteString))
3535parseRequest conn port remoteHost' src1 = do
3636 (src2, headers') <- src1 $$+ takeHeaders
@@ -55,7 +55,7 @@ parseRequest' :: Connection
5555 -> Port
5656 -> [ByteString]
5757 -> SockAddr
58− -> ResumableSource (ResourceT IO) S.ByteString -- FIXME was buffered
58+ -> ResumableSource (ResourceT IO) ByteString -- FIXME was buffered
5959 -> ResourceT IO (Request, IO (ResumableSource (ResourceT IO) ByteString))
6060parseRequest' _ _ [] _ _ = throwIO $ NotEnoughLines []
6161parseRequest' conn port (firstLine:otherLines) remoteHost' src = do
@@ -114,7 +114,7 @@ parseFirst s =
114114 case filter (not . S.null) $ S.splitWith (\c -> c == 32 || c == 9) s of -- ' '
115115 (method:query:http'') -> do
116116 let http' = S.concat http''
117− (hfirst, hsecond) = B.splitAt 5 http'
117+ (hfirst, hsecond) = S.splitAt 5 http'
118118 if hfirst == "HTTP/"
119119 then let (rpath, qstring) = S.breakByte 63 query -- '?'
120120 hv =
@@ -209,6 +209,6 @@ push (THStatus len lines prepend) bs
209209
210210{-# INLINE checkCR #-}
211211checkCR :: ByteString -> Int -> Int
212−checkCR bs pos = if '\r' == B.index bs p then p else pos
212+checkCR bs pos = if 13 == S.index bs p then p else pos -- 13 is CR
213213 where
214214 !p = pos - 1
warp/Network/Wai/Handler/Warp/Response.hs+5−4
@@ -11,7 +11,8 @@ import Blaze.ByteString.Builder.HTTP (chunkedTransferEncoding, chunkedTransferTe
1111import Control.Applicative
1212import Control.Exception
1313import Control.Monad.IO.Class (MonadIO, liftIO)
14−import qualified Data.ByteString.Char8 as B
14+import Data.ByteString (ByteString)
15+import qualified Data.ByteString.Char8 as B (pack)
1516import qualified Data.CaseInsensitive as CI
1617import Data.Conduit
1718import Data.Conduit.Blaze (builderToByteString)
@@ -119,7 +120,7 @@ sendResponse th req conn (ResponseSource s hs bodyFlush)
119120----------------------------------------------------------------
120121
121122-- | Use 'connSendAll' to send this data while respecting timeout rules.
122−connSink :: Connection -> T.Handle -> Sink B.ByteString (ResourceT IO) ()
123+connSink :: Connection -> T.Handle -> Sink ByteString (ResourceT IO) ()
123124connSink Connection { connSendAll = send } th =
124125 sink
125126 where
@@ -166,7 +167,7 @@ infoFromResponse hs (isPersist,isChunked) = (isKeepAlive, needsChunked)
166167 isKeepAlive = isPersist && (isChunked || hasLength)
167168 hasLength = isJust $ checkLength hs
168169
169−checkLength :: H.ResponseHeaders -> Maybe B.ByteString
170+checkLength :: H.ResponseHeaders -> Maybe ByteString
170171checkLength = lookup H.hContentLength
171172
172173----------------------------------------------------------------
@@ -197,7 +198,7 @@ warpVersionHeader = (hServer, ver)
197198
198199----------------------------------------------------------------
199200
200−composeHeader :: H.HttpVersion -> H.Status -> H.ResponseHeaders -> B.ByteString
201+composeHeader :: H.HttpVersion -> H.Status -> H.ResponseHeaders -> ByteString
201202composeHeader version s hs = RH.composeHeader version s (addServerHeader hs)
202203
203204composeHeaderBuilder :: H.HttpVersion -> H.Status -> H.ResponseHeaders -> Bool -> Builder
warp/Network/Wai/Handler/Warp/Types.hs+3−4
@@ -5,7 +5,6 @@ module Network.Wai.Handler.Warp.Types where
55
66import Control.Exception
77import Data.ByteString (ByteString)
8−import qualified Data.ByteString.Char8 as B
98import Data.Typeable (Typeable)
109import Data.Version (showVersion)
1110import Network.HTTP.Types.Header
@@ -65,9 +64,9 @@ instance Exception InvalidRequest
6564--
6665-- * Every time data is successfully sent to the client, the timeout is tickled.
6766data Connection = Connection
68− { connSendMany :: [B.ByteString] -> IO ()
69− , connSendAll :: B.ByteString -> IO ()
67+ { connSendMany :: [ByteString] -> IO ()
68+ , connSendAll :: ByteString -> IO ()
7069 , connSendFile :: FilePath -> Integer -> Integer -> IO () -> [ByteString] -> IO () -- ^ offset, length
7170 , connClose :: IO ()
72− , connRecv :: IO B.ByteString
71+ , connRecv :: IO ByteString
7372 }