mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-19 11:19:36 +00:00
Cover the non-206 Range paths and drop the duplicated test route
The added test only exercised a 403 with a single range, leaving three paths that were equally broken untested: a suffix range, whose first_pos is still -1 when the bounds asserts are compiled out under NDEBUG; two ranges, where apply_ranges() makes no boundary for a non-206 response and the multipart branch wrote an empty one; and a 2xx that is not a 206, which was validated but still announced the full content length. Fold the copied route back into /streamed-with-range with a status query parameter, following the ?error idiom already used there.
This commit is contained in:
1 parent
6b723fbf9d
commit
5539a66c63
2 files changed
+49
-44
No files matched your search
@@ -11845,16 +11845,15 @@ Server::write_content_with_provider(Stream &strm, const Request &req,
|
||||
};
|
||||
|
||||
if (res.content_length_ > 0) {
|
||||
// Only a 206 response is served as a partial representation. That is the
|
||||
// condition `apply_ranges()` used when it decided the Content-Length and
|
||||
// the multipart boundary, and `detail::range_error()` only validates
|
||||
// `req.ranges` against the content length for a 2xx status. Honouring the
|
||||
// ranges here under any other status would write a body that disagrees
|
||||
// with the header we already sent, from an offset nothing has checked.
|
||||
auto partial =
|
||||
// Only a 206 response is served as a partial representation, matching the
|
||||
// condition `apply_ranges()` used to decide the Content-Length and the
|
||||
// multipart boundary. Since `detail::range_error()` validates `req.ranges`
|
||||
// only for a 2xx status, slicing under any other status would write a body
|
||||
// that disagrees with the header already sent, from an unchecked offset.
|
||||
auto is_partial =
|
||||
!req.ranges.empty() && res.status == StatusCode::PartialContent_206;
|
||||
|
||||
if (!partial) {
|
||||
if (!is_partial) {
|
||||
return detail::write_content(strm, res.content_provider_, 0,
|
||||
res.content_length_, is_shutting_down);
|
||||
} else if (req.ranges.size() == 1) {
|
||||
|
||||
Reference in new issue
Block a user