mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-10 09:43:51 +00:00
Code cleanup
This commit is contained in:
parent
bc4a613b6d
commit
bf8fc11b53
68
httplib.h
68
httplib.h
@ -2906,42 +2906,39 @@ inline bool parse_multipart_boundary(const std::string &content_type,
|
|||||||
return !boundary.empty();
|
return !boundary.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool parse_range_header(const std::string &s, Ranges &ranges) {
|
inline bool parse_range_header(const std::string &s, Ranges &ranges) try {
|
||||||
try {
|
static auto re_first_range = std::regex(R"(bytes=(\d*-\d*(?:,\s*\d*-\d*)*))");
|
||||||
static auto re_first_range =
|
std::smatch m;
|
||||||
std::regex(R"(bytes=(\d*-\d*(?:,\s*\d*-\d*)*))");
|
if (std::regex_match(s, m, re_first_range)) {
|
||||||
std::smatch m;
|
auto pos = static_cast<size_t>(m.position(1));
|
||||||
if (std::regex_match(s, m, re_first_range)) {
|
auto len = static_cast<size_t>(m.length(1));
|
||||||
auto pos = static_cast<size_t>(m.position(1));
|
bool all_valid_ranges = true;
|
||||||
auto len = static_cast<size_t>(m.length(1));
|
split(&s[pos], &s[pos + len], ',', [&](const char *b, const char *e) {
|
||||||
bool all_valid_ranges = true;
|
if (!all_valid_ranges) return;
|
||||||
split(&s[pos], &s[pos + len], ',', [&](const char *b, const char *e) {
|
static auto re_another_range = std::regex(R"(\s*(\d*)-(\d*))");
|
||||||
if (!all_valid_ranges) return;
|
std::cmatch cm;
|
||||||
static auto re_another_range = std::regex(R"(\s*(\d*)-(\d*))");
|
if (std::regex_match(b, e, cm, re_another_range)) {
|
||||||
std::cmatch cm;
|
ssize_t first = -1;
|
||||||
if (std::regex_match(b, e, cm, re_another_range)) {
|
if (!cm.str(1).empty()) {
|
||||||
ssize_t first = -1;
|
first = static_cast<ssize_t>(std::stoll(cm.str(1)));
|
||||||
if (!cm.str(1).empty()) {
|
|
||||||
first = static_cast<ssize_t>(std::stoll(cm.str(1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t last = -1;
|
|
||||||
if (!cm.str(2).empty()) {
|
|
||||||
last = static_cast<ssize_t>(std::stoll(cm.str(2)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (first != -1 && last != -1 && first > last) {
|
|
||||||
all_valid_ranges = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ranges.emplace_back(std::make_pair(first, last));
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
return all_valid_ranges;
|
ssize_t last = -1;
|
||||||
}
|
if (!cm.str(2).empty()) {
|
||||||
return false;
|
last = static_cast<ssize_t>(std::stoll(cm.str(2)));
|
||||||
} catch (...) { return false; }
|
}
|
||||||
}
|
|
||||||
|
if (first != -1 && last != -1 && first > last) {
|
||||||
|
all_valid_ranges = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ranges.emplace_back(std::make_pair(first, last));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return all_valid_ranges;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (...) { return false; }
|
||||||
|
|
||||||
class MultipartFormDataParser {
|
class MultipartFormDataParser {
|
||||||
public:
|
public:
|
||||||
@ -4500,7 +4497,6 @@ inline bool Server::routing(Request &req, Response &res, Stream &strm) {
|
|||||||
|
|
||||||
inline bool Server::dispatch_request(Request &req, Response &res,
|
inline bool Server::dispatch_request(Request &req, Response &res,
|
||||||
const Handlers &handlers) {
|
const Handlers &handlers) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (const auto &x : handlers) {
|
for (const auto &x : handlers) {
|
||||||
const auto &pattern = x.first;
|
const auto &pattern = x.first;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user