Skip to content

Commit ee4a6e2

Browse files
committed
cont : fix httplib version
ggml-ci
1 parent fd4c9b2 commit ee4a6e2

File tree

2 files changed

+15
-47
lines changed

2 files changed

+15
-47
lines changed

scripts/sync_vendor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
"https://raw.githubusercontent.com/nothings/stb/refs/heads/master/stb_image.h": "tools/mtmd/vendor/stb_image.h",
1111

12-
"https://raw.githubusercontent.com/mackron/miniaudio/refs/heads/master/miniaudio.h": "tools/mtmd/vendor/miniaudio.h",
12+
"https://github.com/mackron/miniaudio/raw/refs/tags/0.11.22/miniaudio.h": "tools/mtmd/vendor/miniaudio.h",
1313

14-
"https://raw.githubusercontent.com/yhirose/cpp-httplib/refs/heads/master/httplib.h": "tools/server/httplib.h",
14+
"https://raw.githubusercontent.com/yhirose/cpp-httplib/refs/tags/v0.20.1/httplib.h": "tools/server/httplib.h",
1515
}
1616

1717
import urllib.request

tools/server/httplib.h

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,8 @@ using ssize_t = long;
192192
#include <winsock2.h>
193193
#include <ws2tcpip.h>
194194

195-
#if defined(__has_include)
196-
#if __has_include(<afunix.h>)
197195
// afunix.h uses types declared in winsock2.h, so has to be included after it.
198196
#include <afunix.h>
199-
#define CPPHTTPLIB_HAVE_AFUNIX_H 1
200-
#endif
201-
#endif
202197

203198
#ifndef WSA_FLAG_NO_HANDLE_INHERIT
204199
#define WSA_FLAG_NO_HANDLE_INHERIT 0x80
@@ -636,7 +631,6 @@ using Ranges = std::vector<Range>;
636631
struct Request {
637632
std::string method;
638633
std::string path;
639-
std::string matched_route;
640634
Params params;
641635
Headers headers;
642636
std::string body;
@@ -888,16 +882,10 @@ namespace detail {
888882

889883
class MatcherBase {
890884
public:
891-
MatcherBase(std::string pattern) : pattern_(pattern) {}
892885
virtual ~MatcherBase() = default;
893886

894-
const std::string &pattern() const { return pattern_; }
895-
896887
// Match request path and populate its matches and
897888
virtual bool match(Request &request) const = 0;
898-
899-
private:
900-
std::string pattern_;
901889
};
902890

903891
/**
@@ -949,8 +937,7 @@ class PathParamsMatcher final : public MatcherBase {
949937
*/
950938
class RegexMatcher final : public MatcherBase {
951939
public:
952-
RegexMatcher(const std::string &pattern)
953-
: MatcherBase(pattern), regex_(pattern) {}
940+
RegexMatcher(const std::string &pattern) : regex_(pattern) {}
954941

955942
bool match(Request &request) const override;
956943

@@ -1017,12 +1004,9 @@ class Server {
10171004
}
10181005

10191006
Server &set_exception_handler(ExceptionHandler handler);
1020-
10211007
Server &set_pre_routing_handler(HandlerWithResponse handler);
10221008
Server &set_post_routing_handler(Handler handler);
10231009

1024-
Server &set_pre_request_handler(HandlerWithResponse handler);
1025-
10261010
Server &set_expect_100_continue_handler(Expect100ContinueHandler handler);
10271011
Server &set_logger(Logger logger);
10281012

@@ -1103,7 +1087,8 @@ class Server {
11031087
bool listen_internal();
11041088

11051089
bool routing(Request &req, Response &res, Stream &strm);
1106-
bool handle_file_request(const Request &req, Response &res);
1090+
bool handle_file_request(const Request &req, Response &res,
1091+
bool head = false);
11071092
bool dispatch_request(Request &req, Response &res,
11081093
const Handlers &handlers) const;
11091094
bool dispatch_request_for_content_reader(
@@ -1164,7 +1149,6 @@ class Server {
11641149
ExceptionHandler exception_handler_;
11651150
HandlerWithResponse pre_routing_handler_;
11661151
Handler post_routing_handler_;
1167-
HandlerWithResponse pre_request_handler_;
11681152
Expect100ContinueHandler expect_100_continue_handler_;
11691153

11701154
Logger logger_;
@@ -2082,9 +2066,7 @@ template <size_t N> inline constexpr size_t str_len(const char (&)[N]) {
20822066
}
20832067

20842068
inline bool is_numeric(const std::string &str) {
2085-
return !str.empty() &&
2086-
std::all_of(str.cbegin(), str.cend(),
2087-
[](unsigned char c) { return std::isdigit(c); });
2069+
return !str.empty() && std::all_of(str.begin(), str.end(), ::isdigit);
20882070
}
20892071

20902072
inline uint64_t get_header_value_u64(const Headers &headers,
@@ -3568,7 +3550,6 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
35683550
hints.ai_flags = socket_flags;
35693551
}
35703552

3571-
#if !defined(_WIN32) || defined(CPPHTTPLIB_HAVE_AFUNIX_H)
35723553
if (hints.ai_family == AF_UNIX) {
35733554
const auto addrlen = host.length();
35743555
if (addrlen > sizeof(sockaddr_un::sun_path)) { return INVALID_SOCKET; }
@@ -3613,7 +3594,6 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
36133594
}
36143595
return sock;
36153596
}
3616-
#endif
36173597

36183598
auto service = std::to_string(port);
36193599

@@ -6236,8 +6216,7 @@ inline time_t BufferStream::duration() const { return 0; }
62366216

62376217
inline const std::string &BufferStream::get_buffer() const { return buffer; }
62386218

6239-
inline PathParamsMatcher::PathParamsMatcher(const std::string &pattern)
6240-
: MatcherBase(pattern) {
6219+
inline PathParamsMatcher::PathParamsMatcher(const std::string &pattern) {
62416220
constexpr const char marker[] = "/:";
62426221

62436222
// One past the last ending position of a path param substring
@@ -6488,11 +6467,6 @@ inline Server &Server::set_post_routing_handler(Handler handler) {
64886467
return *this;
64896468
}
64906469

6491-
inline Server &Server::set_pre_request_handler(HandlerWithResponse handler) {
6492-
pre_request_handler_ = std::move(handler);
6493-
return *this;
6494-
}
6495-
64966470
inline Server &Server::set_logger(Logger logger) {
64976471
logger_ = std::move(logger);
64986472
return *this;
@@ -6904,7 +6878,8 @@ Server::read_content_core(Stream &strm, Request &req, Response &res,
69046878
return true;
69056879
}
69066880

6907-
inline bool Server::handle_file_request(const Request &req, Response &res) {
6881+
inline bool Server::handle_file_request(const Request &req, Response &res,
6882+
bool head) {
69086883
for (const auto &entry : base_dirs_) {
69096884
// Prefix match
69106885
if (!req.path.compare(0, entry.mount_point.size(), entry.mount_point)) {
@@ -6937,7 +6912,7 @@ inline bool Server::handle_file_request(const Request &req, Response &res) {
69376912
return true;
69386913
});
69396914

6940-
if (req.method != "HEAD" && file_request_handler_) {
6915+
if (!head && file_request_handler_) {
69416916
file_request_handler_(req, res);
69426917
}
69436918

@@ -7071,8 +7046,9 @@ inline bool Server::routing(Request &req, Response &res, Stream &strm) {
70717046
}
70727047

70737048
// File handler
7074-
if ((req.method == "GET" || req.method == "HEAD") &&
7075-
handle_file_request(req, res)) {
7049+
auto is_head_request = req.method == "HEAD";
7050+
if ((req.method == "GET" || is_head_request) &&
7051+
handle_file_request(req, res, is_head_request)) {
70767052
return true;
70777053
}
70787054

@@ -7147,11 +7123,7 @@ inline bool Server::dispatch_request(Request &req, Response &res,
71477123
const auto &handler = x.second;
71487124

71497125
if (matcher->match(req)) {
7150-
req.matched_route = matcher->pattern();
7151-
if (!pre_request_handler_ ||
7152-
pre_request_handler_(req, res) != HandlerResponse::Handled) {
7153-
handler(req, res);
7154-
}
7126+
handler(req, res);
71557127
return true;
71567128
}
71577129
}
@@ -7278,11 +7250,7 @@ inline bool Server::dispatch_request_for_content_reader(
72787250
const auto &handler = x.second;
72797251

72807252
if (matcher->match(req)) {
7281-
req.matched_route = matcher->pattern();
7282-
if (!pre_request_handler_ ||
7283-
pre_request_handler_(req, res) != HandlerResponse::Handled) {
7284-
handler(req, res, content_reader);
7285-
}
7253+
handler(req, res, content_reader);
72867254
return true;
72877255
}
72887256
}

0 commit comments

Comments
 (0)