Respond with 200 or 206 in ranged responses

This commit is contained in:
Joe Nelson
2014-09-07 09:38:30 -07:00
parent 7c93c788fa
commit 7802fa5b7e
6 changed files with 183 additions and 28 deletions
+10 -4
View File
@@ -96,17 +96,23 @@ app conn req respond = do
respondWithRangedResult :: RangedResult -> Response
respondWithRangedResult rr =
responseLBS status206 [
responseLBS status [
jsonContentType,
("Content-Range",
if rrTotal rr == 0
then "*/0"
else (BS.pack . show . rrFrom ) rr <> "-"
<> (BS.pack . show . rrTo ) rr <> "/"
<> (BS.pack . show . rrTotal) rr
else (BS.pack $ show from) <> "-"
<> (BS.pack $ show to) <> "/"
<> (BS.pack $ show total)
)
] (rrBody rr)
where
from = rrFrom rr
to = rrTo rr
total = rrTotal rr
status = if (1 + to - from) < total then status206 else status200
requestedVersion :: RequestHeaders -> Maybe Int
requestedVersion hdrs =
case verStr of