@@ -6,13 +6,12 @@ module Network.Wai.Handler.Warp.File (
66 RspFileInfo(..)
77 , conditionalRequest
88 , addContentHeadersForFilePart
9− , parseByteRanges
9+ , H.parseByteRanges
1010 ) where
1111
1212import Control.Applicative ((<|>))
1313import Data.Array ((!))
14−import qualified Data.ByteString as B hiding (pack)
15−import qualified Data.ByteString.Char8 as B (pack, readInteger)
14+import qualified Data.ByteString.Char8 as B (pack)
1615import Data.ByteString (ByteString)
1716import Data.Maybe (fromMaybe)
1817import Network.HTTP.Date
@@ -99,7 +98,7 @@ unconditional reqidx size = case reqidx ! fromEnum ReqRange of
9998----------------------------------------------------------------
10099
101100parseRange :: ByteString -> Integer -> RspFileInfo
102−parseRange rng size = case parseByteRanges rng of
101+parseRange rng size = case H.parseByteRanges rng of
103102 Nothing -> WithoutBody H.requestedRangeNotSatisfiable416
104103 Just [] -> WithoutBody H.requestedRangeNotSatisfiable416
105104 Just (r:_) -> let (!beg, !end) = checkRange r size
@@ -115,33 +114,6 @@ checkRange (H.ByteRangeFrom beg) size = (beg, size - 1)
115114checkRange (H.ByteRangeFromTo beg end) size = (beg, min (size - 1) end)
116115checkRange (H.ByteRangeSuffix count) size = (max 0 (size - count), size - 1)
117116
118−-- | Parse the value of a Range header into a 'H.ByteRanges'.
119−parseByteRanges :: B.ByteString -> Maybe H.ByteRanges
120−parseByteRanges bs1 = do
121− bs2 <- stripPrefix "bytes=" bs1
122− (r, bs3) <- range bs2
123− ranges (r:) bs3
124− where
125− range bs2 = do
126− (i, bs3) <- B.readInteger bs2
127− if i < 0 -- has prefix "-" ("-0" is not valid, but here treated as "0-")
128− then Just (H.ByteRangeSuffix (negate i), bs3)
129− else do
130− bs4 <- stripPrefix "-" bs3
131− case B.readInteger bs4 of
132− Just (j, bs5) | j >= i -> Just (H.ByteRangeFromTo i j, bs5)
133− _ -> Just (H.ByteRangeFrom i, bs4)
134− ranges front bs3
135− | B.null bs3 = Just (front [])
136− | otherwise = do
137− bs4 <- stripPrefix "," bs3
138− (r, bs5) <- range bs4
139− ranges (front . (r:)) bs5
140−
141− stripPrefix x y
142− | x `B.isPrefixOf` y = Just (B.drop (B.length x) y)
143− | otherwise = Nothing
144−
145117----------------------------------------------------------------
146118
147119contentRange :: H.HeaderName