fix: range request with first position same as length return status 206
This commit is contained in:
committed by
Steve Chavez
parent
07fef25591
commit
8eed576826
@@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- #2899, Fix `application/vnd.pgrst.array` not accepted as a valid mediatype - @taimoorzaeem
|
||||
- #2524, Fix schema cache and configuration reloading with `NOTIFY` not working on Windows - @diogob, @laurenceisla
|
||||
- #2915, Fix duplicate headers in response - @taimoorzaeem
|
||||
- #2824, Fix range request with first position same as length return status 206 - @taimoorzaeem
|
||||
|
||||
## [11.2.0] - 2023-08-10
|
||||
|
||||
|
||||
@@ -104,9 +104,9 @@ rangeStatusHeader topLevelRange queryTotal tableTotal =
|
||||
rangeStatus :: Integer -> Integer -> Maybe Integer -> Status
|
||||
rangeStatus _ _ Nothing = status200
|
||||
rangeStatus lower upper (Just total)
|
||||
| lower > total = status416 -- 416 Range Not Satisfiable
|
||||
| (1 + upper - lower) < total = status206 -- 206 Partial Content
|
||||
| otherwise = status200 -- 200 OK
|
||||
| lower >= total && lower /= upper = 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 =
|
||||
|
||||
@@ -453,3 +453,17 @@ spec = do
|
||||
{ matchStatus = 416
|
||||
, matchHeaders = ["Content-Range" <:> "*/15"]
|
||||
}
|
||||
|
||||
it "refuses a range with first position the same as number of items" $
|
||||
request methodGet "/rpc/getitemrange?min=1&max=2"
|
||||
(rangeHdrsWithCount $ ByteRangeFromTo 1 2) mempty
|
||||
`shouldRespondWith`
|
||||
[json| {
|
||||
"message":"Requested range not satisfiable",
|
||||
"code":"PGRST103",
|
||||
"details":"An offset of 1 was requested, but there are only 1 rows.",
|
||||
"hint":null
|
||||
}|]
|
||||
{ matchStatus = 416
|
||||
, matchHeaders = ["Content-Range" <:> "*/1"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user