Merge pull request #283 from barryam3/noexcept

Remove use of exceptions.
This commit is contained in:
yhirose 2019-12-05 21:32:06 -05:00 committed by GitHub
commit 66719ae3d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1881,15 +1881,16 @@ inline bool parse_multipart_boundary(const std::string &content_type,
}
inline bool parse_range_header(const std::string &s, Ranges &ranges) {
try {
static auto re_first_range =
std::regex(R"(bytes=(\d*-\d*(?:,\s*\d*-\d*)*))");
std::smatch m;
if (std::regex_match(s, m, re_first_range)) {
auto pos = m.position(1);
auto len = m.length(1);
bool all_valid_ranges = true;
detail::split(
&s[pos], &s[pos + len], ',', [&](const char *b, const char *e) {
if (!all_valid_ranges) return;
static auto re_another_range = std::regex(R"(\s*(\d*)-(\d*))");
std::cmatch m;
if (std::regex_match(b, e, m, re_another_range)) {
@ -1904,15 +1905,15 @@ inline bool parse_range_header(const std::string &s, Ranges &ranges) {
}
if (first != -1 && last != -1 && first > last) {
throw std::runtime_error("invalid range error");
all_valid_ranges = false;
return;
}
ranges.emplace_back(std::make_pair(first, last));
}
});
return true;
return all_valid_ranges;
}
return false;
} catch (...) { return false; }
}
class MultipartFormDataParser {