mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-10 09:43:51 +00:00
Merge pull request #283 from barryam3/noexcept
Remove use of exceptions.
This commit is contained in:
commit
66719ae3d4
@ -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) {
|
inline bool parse_range_header(const std::string &s, Ranges &ranges) {
|
||||||
try {
|
|
||||||
static auto re_first_range =
|
static auto re_first_range =
|
||||||
std::regex(R"(bytes=(\d*-\d*(?:,\s*\d*-\d*)*))");
|
std::regex(R"(bytes=(\d*-\d*(?:,\s*\d*-\d*)*))");
|
||||||
std::smatch m;
|
std::smatch m;
|
||||||
if (std::regex_match(s, m, re_first_range)) {
|
if (std::regex_match(s, m, re_first_range)) {
|
||||||
auto pos = m.position(1);
|
auto pos = m.position(1);
|
||||||
auto len = m.length(1);
|
auto len = m.length(1);
|
||||||
|
bool all_valid_ranges = true;
|
||||||
detail::split(
|
detail::split(
|
||||||
&s[pos], &s[pos + len], ',', [&](const char *b, const char *e) {
|
&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*))");
|
static auto re_another_range = std::regex(R"(\s*(\d*)-(\d*))");
|
||||||
std::cmatch m;
|
std::cmatch m;
|
||||||
if (std::regex_match(b, e, m, re_another_range)) {
|
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) {
|
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));
|
ranges.emplace_back(std::make_pair(first, last));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return all_valid_ranges;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} catch (...) { return false; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MultipartFormDataParser {
|
class MultipartFormDataParser {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user