mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2026-08-27 01:04:19 +00:00
vendor : update cpp-httplib to 0.53.1 (#27103)
This commit is contained in:
parent
5f754ea0e2
commit
77140d247c
3 changed files with 51 additions and 14 deletions
38
vendor/cpp-httplib/httplib.cpp
vendored
38
vendor/cpp-httplib/httplib.cpp
vendored
|
|
@ -7146,6 +7146,10 @@ PathParamsMatcher::PathParamsMatcher(const std::string &pattern)
|
|||
bool PathParamsMatcher::match(Request &request) const {
|
||||
request.matches = std::smatch();
|
||||
request.path_params.clear();
|
||||
|
||||
// A pattern without parameters is just a literal path to compare against
|
||||
if (param_names_.empty()) { return request.path == pattern(); }
|
||||
|
||||
request.path_params.reserve(param_names_.size());
|
||||
|
||||
// One past the position at which the path matched the pattern last time
|
||||
|
|
@ -7188,6 +7192,11 @@ bool PathParamsMatcher::match(Request &request) const {
|
|||
|
||||
bool RegexMatcher::match(Request &request) const {
|
||||
request.path_params.clear();
|
||||
// See CPPHTTPLIB_REGEX_ROUTE_PATH_MAX_LENGTH: an overlong path is treated as
|
||||
// a non-match rather than risking a stack overflow in std::regex_match.
|
||||
if (request.path.length() > CPPHTTPLIB_REGEX_ROUTE_PATH_MAX_LENGTH) {
|
||||
return false;
|
||||
}
|
||||
return std::regex_match(request.path, request.matches, regex_);
|
||||
}
|
||||
|
||||
|
|
@ -7613,11 +7622,21 @@ Server::~Server() = default;
|
|||
|
||||
std::unique_ptr<detail::MatcherBase>
|
||||
Server::make_matcher(const std::string &pattern) {
|
||||
// Path params take precedence, so "/users/:id/(.*)" keeps being matched as
|
||||
// a path params pattern
|
||||
if (pattern.find("/:") != std::string::npos) {
|
||||
return detail::make_unique<detail::PathParamsMatcher>(pattern);
|
||||
} else {
|
||||
return detail::make_unique<detail::RegexMatcher>(pattern);
|
||||
}
|
||||
|
||||
// A pattern with no regex metacharacter only has to be compared literally,
|
||||
// which is what PathParamsMatcher already does when it captures no
|
||||
// parameter, so std::regex is only worth building for the patterns that
|
||||
// actually need it
|
||||
if (pattern.find_first_of(".^$|()[]{}*+?\\") == std::string::npos) {
|
||||
return detail::make_unique<detail::PathParamsMatcher>(pattern);
|
||||
}
|
||||
|
||||
return detail::make_unique<detail::RegexMatcher>(pattern);
|
||||
}
|
||||
|
||||
Server &Server::Get(const std::string &pattern, Handler handler) {
|
||||
|
|
@ -8259,15 +8278,12 @@ bool Server::read_content_core(
|
|||
}
|
||||
}
|
||||
if (has_data) {
|
||||
auto result =
|
||||
detail::read_content_without_length(strm, payload_max_length_, out);
|
||||
if (result == detail::ReadContentResult::PayloadTooLarge) {
|
||||
res.status = StatusCode::PayloadTooLarge_413;
|
||||
return false;
|
||||
} else if (result != detail::ReadContentResult::Success) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
// Route through the same decompressing reader used by the
|
||||
// length-framed and chunked paths below, so payload_max_length_ is
|
||||
// enforced on the decompressed size here too instead of only on the
|
||||
// compressed wire bytes.
|
||||
return detail::read_content(strm, req, payload_max_length_, res.status,
|
||||
nullptr, out, true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue