fix: range request with 0 rows and 0 offset return status 416 (#2991)
This commit is contained in:
@@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- #2771, Add `Server-Timing` header with JWT duration - @taimoorzaeem
|
||||
- #2698, Add config `jwt-cache-max-lifetime` and implement JWT caching - @taimoorzaeem
|
||||
- #2943, Add `handling=strict/lenient` for Prefer header - @taimoorzaeem
|
||||
- #2824, Fix range request with 0 rows and 0 offset return status 416 - @strengthless
|
||||
|
||||
## [11.2.1] - 2023-10-03
|
||||
|
||||
|
||||
@@ -104,9 +104,9 @@ rangeStatusHeader topLevelRange queryTotal tableTotal =
|
||||
rangeStatus :: Integer -> Integer -> Maybe Integer -> Status
|
||||
rangeStatus _ _ Nothing = status200
|
||||
rangeStatus lower upper (Just total)
|
||||
| lower >= total && lower /= upper = status416 -- 416 Range Not Satisfiable
|
||||
| (1 + upper - lower) < total = status206 -- 206 Partial Content
|
||||
| otherwise = status200 -- 200 OK
|
||||
| lower >= total && lower /= upper && lower /= 0 = status416 -- 416 Range Not Satisfiable
|
||||
| (1 + upper - lower) < total = status206 -- 206 Partial Content
|
||||
| otherwise = status200 -- 200 OK
|
||||
|
||||
contentRangeH :: (Integral a, Show a) => a -> a -> Maybe a -> Header
|
||||
contentRangeH lower upper total =
|
||||
|
||||
@@ -413,6 +413,15 @@ spec = do
|
||||
matchHeader "Content-Range" "10-14/*"
|
||||
simpleStatus r `shouldBe` ok200
|
||||
|
||||
it "does not throw error when offset is 0 and and total is 0" $
|
||||
request methodGet "/rpc/getitemrange?min=0&max=0"
|
||||
(rangeHdrsWithCount $ ByteRangeFromTo 0 1) mempty
|
||||
`shouldRespondWith`
|
||||
[json|[]|]
|
||||
{ matchStatus = 200
|
||||
, matchHeaders = ["Content-Range" <:> "*/0"]
|
||||
}
|
||||
|
||||
context "of invalid range" $ do
|
||||
it "fails with 416 for offside range" $
|
||||
request methodGet "/items"
|
||||
|
||||
Reference in New Issue
Block a user