mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-13 10:24:47 +00:00
Compare the Range unit case-insensitively
RFC 9110 §14.1 makes range unit names case-insensitive, but parse_range_header() matched "bytes=" exactly, so a request with Range: Bytes=1-3 was answered with 416.
This commit is contained in:
@@ -9189,7 +9189,7 @@ inline bool parse_range_header(const std::string &s, Ranges &ranges) try {
|
||||
return std::all_of(str.cbegin(), str.cend(), is_ascii_digit);
|
||||
};
|
||||
|
||||
if (s.size() > 7 && s.compare(0, 6, "bytes=") == 0) {
|
||||
if (s.size() > 7 && case_ignore::equal(s.substr(0, 6), "bytes=")) {
|
||||
const auto pos = static_cast<size_t>(6);
|
||||
const auto len = static_cast<size_t>(s.size() - 6);
|
||||
auto all_valid_ranges = true;
|
||||
|
||||
@@ -2033,6 +2033,13 @@ TEST(ParseHeaderValueTest, Range) {
|
||||
EXPECT_EQ(0, ranges[0].first);
|
||||
EXPECT_EQ(-1, ranges[0].second);
|
||||
}
|
||||
|
||||
// RFC 9110 14.1: range unit names are case-insensitive.
|
||||
for (const auto &s : {"Bytes=1-10", "BYTES=1-10", "bYtEs=1-10"}) {
|
||||
Ranges ranges;
|
||||
EXPECT_TRUE(detail::parse_range_header(s, ranges)) << s;
|
||||
EXPECT_EQ((Ranges{{1, 10}}), ranges) << s;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ParseAcceptEncoding1, AcceptEncoding) {
|
||||
|
||||
Reference in New Issue
Block a user