Accurate range response headers

This commit is contained in:
Joe Nelson
2014-08-04 22:30:38 -07:00
parent 351b44ed52
commit 81929dd513
2 changed files with 9 additions and 3 deletions
+4 -2
View File
@@ -91,8 +91,10 @@ respondWithRangedResult rr =
responseLBS status206 [
json,
("Content-Range",
"0-" <> (BS.pack . show . rrTo) rr <> "/"
<> (BS.pack . show . rrTotal) rr)
(BS.pack . show . rrFrom ) rr <> "-"
<> (BS.pack . show . rrTo ) rr <> "/"
<> (BS.pack . show . rrTotal) rr
)
] (rrBody rr)
where
+5 -1
View File
@@ -41,9 +41,13 @@ getRows schema table qq range conn = do
return $ case r of
[[total, limited_total, json]] ->
RangedResult 0 (fromSql limited_total) (fromSql total) (fromSql json)
RangedResult offset (offset + fromSql limited_total - 1)
(fromSql total) (fromSql json)
_ -> RangedResult 0 0 0 ""
where
offset = fromMaybe 0 $ R.offset <$> range
whereClause :: Net.Query -> QuotedSql
whereClause qs =
if null qs then ("", []) else (" where ", []) <> conjunction