revert
This commit is contained in:
211
3rd_party/cpp-httplib/httplib.h
vendored
211
3rd_party/cpp-httplib/httplib.h
vendored
@@ -8,7 +8,7 @@
|
||||
#ifndef CPPHTTPLIB_HTTPLIB_H
|
||||
#define CPPHTTPLIB_HTTPLIB_H
|
||||
|
||||
#define CPPHTTPLIB_VERSION "0.14.0"
|
||||
#define CPPHTTPLIB_VERSION "0.14.2"
|
||||
|
||||
/*
|
||||
* Configuration
|
||||
@@ -247,7 +247,6 @@ using socket_t = int;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment(lib, "crypt32.lib")
|
||||
#pragma comment(lib, "cryptui.lib")
|
||||
#endif
|
||||
#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && defined(__APPLE__)
|
||||
#include <TargetConditionals.h>
|
||||
@@ -331,7 +330,7 @@ struct scope_exit {
|
||||
explicit scope_exit(std::function<void(void)> &&f)
|
||||
: exit_function(std::move(f)), execute_on_destruction{true} {}
|
||||
|
||||
scope_exit(scope_exit &&rhs)
|
||||
scope_exit(scope_exit &&rhs) noexcept
|
||||
: exit_function(std::move(rhs.exit_function)),
|
||||
execute_on_destruction{rhs.execute_on_destruction} {
|
||||
rhs.release();
|
||||
@@ -385,6 +384,7 @@ public:
|
||||
DataSink &operator=(DataSink &&) = delete;
|
||||
|
||||
std::function<bool(const char *data, size_t data_len)> write;
|
||||
std::function<bool()> is_writable;
|
||||
std::function<void()> done;
|
||||
std::function<void(const Headers &trailer)> done_with_trailer;
|
||||
std::ostream os;
|
||||
@@ -395,7 +395,7 @@ private:
|
||||
explicit data_sink_streambuf(DataSink &sink) : sink_(sink) {}
|
||||
|
||||
protected:
|
||||
std::streamsize xsputn(const char *s, std::streamsize n) {
|
||||
std::streamsize xsputn(const char *s, std::streamsize n) override {
|
||||
sink_.write(s, static_cast<size_t>(n));
|
||||
return n;
|
||||
}
|
||||
@@ -873,15 +873,15 @@ private:
|
||||
bool routing(Request &req, Response &res, Stream &strm);
|
||||
bool handle_file_request(const Request &req, Response &res,
|
||||
bool head = false);
|
||||
bool dispatch_request(Request &req, Response &res, const Handlers &handlers);
|
||||
bool
|
||||
dispatch_request_for_content_reader(Request &req, Response &res,
|
||||
ContentReader content_reader,
|
||||
const HandlersForContentReader &handlers);
|
||||
bool dispatch_request(Request &req, Response &res,
|
||||
const Handlers &handlers) const;
|
||||
bool dispatch_request_for_content_reader(
|
||||
Request &req, Response &res, ContentReader content_reader,
|
||||
const HandlersForContentReader &handlers) const;
|
||||
|
||||
bool parse_request_line(const char *s, Request &req);
|
||||
bool parse_request_line(const char *s, Request &req) const;
|
||||
void apply_ranges(const Request &req, Response &res,
|
||||
std::string &content_type, std::string &boundary);
|
||||
std::string &content_type, std::string &boundary) const;
|
||||
bool write_response(Stream &strm, bool close_connection, const Request &req,
|
||||
Response &res);
|
||||
bool write_response_with_content(Stream &strm, bool close_connection,
|
||||
@@ -901,7 +901,7 @@ private:
|
||||
bool read_content_core(Stream &strm, Request &req, Response &res,
|
||||
ContentReceiver receiver,
|
||||
MultipartContentHeader multipart_header,
|
||||
ContentReceiver multipart_receiver);
|
||||
ContentReceiver multipart_receiver) const;
|
||||
|
||||
virtual bool process_and_close_socket(socket_t sock);
|
||||
|
||||
@@ -967,7 +967,7 @@ enum class Error {
|
||||
SSLPeerCouldBeClosed_,
|
||||
};
|
||||
|
||||
std::string to_string(const Error error);
|
||||
std::string to_string(Error error);
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const Error &obj);
|
||||
|
||||
@@ -1226,7 +1226,7 @@ public:
|
||||
void set_ca_cert_path(const std::string &ca_cert_file_path,
|
||||
const std::string &ca_cert_dir_path = std::string());
|
||||
void set_ca_cert_store(X509_STORE *ca_cert_store);
|
||||
X509_STORE *create_ca_cert_store(const char *ca_cert, std::size_t size);
|
||||
X509_STORE *create_ca_cert_store(const char *ca_cert, std::size_t size) const;
|
||||
#endif
|
||||
|
||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
@@ -1255,14 +1255,14 @@ protected:
|
||||
// Also, shutdown_ssl and close_socket should also NOT be called concurrently
|
||||
// with a DIFFERENT thread sending requests using that socket.
|
||||
virtual void shutdown_ssl(Socket &socket, bool shutdown_gracefully);
|
||||
void shutdown_socket(Socket &socket);
|
||||
void shutdown_socket(Socket &socket) const;
|
||||
void close_socket(Socket &socket);
|
||||
|
||||
bool process_request(Stream &strm, Request &req, Response &res,
|
||||
bool close_connection, Error &error);
|
||||
|
||||
bool write_content_with_provider(Stream &strm, const Request &req,
|
||||
Error &error);
|
||||
Error &error) const;
|
||||
|
||||
void copy_settings(const ClientImpl &rhs);
|
||||
|
||||
@@ -1353,7 +1353,8 @@ private:
|
||||
Result send_(Request &&req);
|
||||
|
||||
socket_t create_client_socket(Error &error) const;
|
||||
bool read_response_line(Stream &strm, const Request &req, Response &res);
|
||||
bool read_response_line(Stream &strm, const Request &req,
|
||||
Response &res) const;
|
||||
bool write_request(Stream &strm, Request &req, bool close_connection,
|
||||
Error &error);
|
||||
bool redirect(Request &req, Response &res, Error &error);
|
||||
@@ -1372,7 +1373,7 @@ private:
|
||||
const std::string &content_type);
|
||||
ContentProviderWithoutLength get_multipart_content_provider(
|
||||
const std::string &boundary, const MultipartFormDataItems &items,
|
||||
const MultipartFormDataProviderItems &provider_items);
|
||||
const MultipartFormDataProviderItems &provider_items) const;
|
||||
|
||||
std::string adjust_host_string(const std::string &host) const;
|
||||
|
||||
@@ -1685,7 +1686,7 @@ public:
|
||||
private:
|
||||
bool create_and_connect_socket(Socket &socket, Error &error) override;
|
||||
void shutdown_ssl(Socket &socket, bool shutdown_gracefully) override;
|
||||
void shutdown_ssl_impl(Socket &socket, bool shutdown_socket);
|
||||
void shutdown_ssl_impl(Socket &socket, bool shutdown_gracefully);
|
||||
|
||||
bool process_socket(const Socket &socket,
|
||||
std::function<bool(Stream &strm)> callback) override;
|
||||
@@ -2075,6 +2076,9 @@ std::string trim_copy(const std::string &s);
|
||||
void split(const char *b, const char *e, char d,
|
||||
std::function<void(const char *, const char *)> fn);
|
||||
|
||||
void split(const char *b, const char *e, char d, size_t m,
|
||||
std::function<void(const char *, const char *)> fn);
|
||||
|
||||
bool process_client_socket(socket_t sock, time_t read_timeout_sec,
|
||||
time_t read_timeout_usec, time_t write_timeout_sec,
|
||||
time_t write_timeout_usec,
|
||||
@@ -2151,7 +2155,7 @@ public:
|
||||
|
||||
class nocompressor : public compressor {
|
||||
public:
|
||||
virtual ~nocompressor() = default;
|
||||
~nocompressor() override = default;
|
||||
|
||||
bool compress(const char *data, size_t data_length, bool /*last*/,
|
||||
Callback callback) override;
|
||||
@@ -2161,7 +2165,7 @@ public:
|
||||
class gzip_compressor : public compressor {
|
||||
public:
|
||||
gzip_compressor();
|
||||
~gzip_compressor();
|
||||
~gzip_compressor() override;
|
||||
|
||||
bool compress(const char *data, size_t data_length, bool last,
|
||||
Callback callback) override;
|
||||
@@ -2174,7 +2178,7 @@ private:
|
||||
class gzip_decompressor : public decompressor {
|
||||
public:
|
||||
gzip_decompressor();
|
||||
~gzip_decompressor();
|
||||
~gzip_decompressor() override;
|
||||
|
||||
bool is_valid() const override;
|
||||
|
||||
@@ -2317,7 +2321,7 @@ inline std::string from_i_to_hex(size_t n) {
|
||||
|
||||
inline size_t to_utf8(int code, char *buff) {
|
||||
if (code < 0x0080) {
|
||||
buff[0] = (code & 0x7F);
|
||||
buff[0] = static_cast<char>(code & 0x7F);
|
||||
return 1;
|
||||
} else if (code < 0x0800) {
|
||||
buff[0] = static_cast<char>(0xC0 | ((code >> 6) & 0x1F));
|
||||
@@ -2583,16 +2587,23 @@ inline std::string trim_double_quotes_copy(const std::string &s) {
|
||||
|
||||
inline void split(const char *b, const char *e, char d,
|
||||
std::function<void(const char *, const char *)> fn) {
|
||||
return split(b, e, d, std::numeric_limits<size_t>::max(), fn);
|
||||
}
|
||||
|
||||
inline void split(const char *b, const char *e, char d, size_t m,
|
||||
std::function<void(const char *, const char *)> fn) {
|
||||
size_t i = 0;
|
||||
size_t beg = 0;
|
||||
size_t count = 1;
|
||||
|
||||
while (e ? (b + i < e) : (b[i] != '\0')) {
|
||||
if (b[i] == d) {
|
||||
if (b[i] == d && count < m) {
|
||||
auto r = trim(b, e, beg, i);
|
||||
if (r.first < r.second) {
|
||||
fn(&b[r.first], &b[r.second]);
|
||||
}
|
||||
beg = i + 1;
|
||||
count++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -2683,9 +2694,7 @@ inline mmap::mmap(const char *path)
|
||||
,
|
||||
size_(0),
|
||||
addr_(nullptr) {
|
||||
if (!open(path)) {
|
||||
std::runtime_error("");
|
||||
}
|
||||
open(path);
|
||||
}
|
||||
|
||||
inline mmap::~mmap() { close(); }
|
||||
@@ -2974,7 +2983,7 @@ private:
|
||||
size_t read_buff_off_ = 0;
|
||||
size_t read_buff_content_size_ = 0;
|
||||
|
||||
static const size_t read_buff_size_ = 1024 * 4;
|
||||
static const size_t read_buff_size_ = 1024l * 4;
|
||||
};
|
||||
|
||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
@@ -3109,8 +3118,9 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
|
||||
#ifndef _WIN32
|
||||
if (hints.ai_family == AF_UNIX) {
|
||||
const auto addrlen = host.length();
|
||||
if (addrlen > sizeof(sockaddr_un::sun_path))
|
||||
if (addrlen > sizeof(sockaddr_un::sun_path)) {
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
auto sock = socket(hints.ai_family, hints.ai_socktype, hints.ai_protocol);
|
||||
if (sock != INVALID_SOCKET) {
|
||||
@@ -3324,7 +3334,7 @@ inline socket_t create_client_socket(
|
||||
if (ip_from_if.empty()) {
|
||||
ip_from_if = intf;
|
||||
}
|
||||
if (!bind_ip_address(sock2, ip_from_if.c_str())) {
|
||||
if (!bind_ip_address(sock2, ip_from_if)) {
|
||||
error = Error::BindIPAddress;
|
||||
return false;
|
||||
}
|
||||
@@ -3486,7 +3496,7 @@ find_content_type(const std::string &path,
|
||||
|
||||
auto it = user_data.find(ext);
|
||||
if (it != user_data.end()) {
|
||||
return it->second.c_str();
|
||||
return it->second;
|
||||
}
|
||||
|
||||
using udl::operator""_t;
|
||||
@@ -3752,8 +3762,9 @@ inline bool gzip_decompressor::decompress(const char *data, size_t data_length,
|
||||
}
|
||||
}
|
||||
|
||||
if (ret != Z_OK && ret != Z_STREAM_END)
|
||||
if (ret != Z_OK && ret != Z_STREAM_END) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} while (data_length > 0);
|
||||
|
||||
@@ -4069,7 +4080,7 @@ inline bool read_content_chunked(Stream &strm, T &x,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strcmp(line_reader.ptr(), "\r\n")) {
|
||||
if (strcmp(line_reader.ptr(), "\r\n") != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -4085,7 +4096,7 @@ inline bool read_content_chunked(Stream &strm, T &x,
|
||||
return false;
|
||||
}
|
||||
|
||||
while (strcmp(line_reader.ptr(), "\r\n")) {
|
||||
while (strcmp(line_reader.ptr(), "\r\n") != 0) {
|
||||
if (line_reader.size() > CPPHTTPLIB_HEADER_MAX_LENGTH) {
|
||||
return false;
|
||||
}
|
||||
@@ -4241,6 +4252,8 @@ inline bool write_content(Stream &strm, const ContentProvider &content_provider,
|
||||
return ok;
|
||||
};
|
||||
|
||||
data_sink.is_writable = [&]() -> bool { return strm.is_writable(); };
|
||||
|
||||
while (offset < end_offset && !is_shutting_down()) {
|
||||
if (!strm.is_writable()) {
|
||||
error = Error::Write;
|
||||
@@ -4287,6 +4300,8 @@ write_content_without_length(Stream &strm,
|
||||
return ok;
|
||||
};
|
||||
|
||||
data_sink.is_writable = [&]() -> bool { return strm.is_writable(); };
|
||||
|
||||
data_sink.done = [&](void) { data_available = false; };
|
||||
|
||||
while (data_available && !is_shutting_down()) {
|
||||
@@ -4337,6 +4352,8 @@ write_content_chunked(Stream &strm, const ContentProvider &content_provider,
|
||||
return ok;
|
||||
};
|
||||
|
||||
data_sink.is_writable = [&]() -> bool { return strm.is_writable(); };
|
||||
|
||||
auto done_with_trailer = [&](const Headers *trailer) {
|
||||
if (!ok) {
|
||||
return;
|
||||
@@ -4438,8 +4455,9 @@ inline bool redirect(T &cli, Request &req, Response &res,
|
||||
req = new_req;
|
||||
res = new_res;
|
||||
|
||||
if (res.location.empty())
|
||||
if (res.location.empty()) {
|
||||
res.location = location;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -4534,8 +4552,9 @@ inline bool parse_range_header(const std::string &s, Ranges &ranges) try {
|
||||
auto len = static_cast<size_t>(m.length(1));
|
||||
auto all_valid_ranges = true;
|
||||
split(&s[pos], &s[pos + len], ',', [&](const char *b, const char *e) {
|
||||
if (!all_valid_ranges)
|
||||
if (!all_valid_ranges) {
|
||||
return;
|
||||
}
|
||||
static auto re_another_range = std::regex(R"(\s*(\d*)-(\d*))");
|
||||
std::cmatch cm;
|
||||
if (std::regex_match(b, e, cm, re_another_range)) {
|
||||
@@ -4922,8 +4941,9 @@ serialize_multipart_formdata(const MultipartFormDataItems &items,
|
||||
body += item.content + serialize_multipart_formdata_item_end();
|
||||
}
|
||||
|
||||
if (finish)
|
||||
if (finish) {
|
||||
body += serialize_multipart_formdata_finish(boundary);
|
||||
}
|
||||
|
||||
return body;
|
||||
}
|
||||
@@ -5376,7 +5396,7 @@ inline std::string random_string(size_t length) {
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz";
|
||||
const size_t max_index = (sizeof(charset) - 1);
|
||||
return charset[repertory_rand<size_t>() % max_index];
|
||||
return charset[repertory_rand<std::size_t>() % max_index];
|
||||
};
|
||||
std::string str(length, 0);
|
||||
std::generate_n(str.begin(), length, randchar);
|
||||
@@ -5671,7 +5691,7 @@ inline SocketStream::SocketStream(socket_t sock, time_t read_timeout_sec,
|
||||
write_timeout_usec_(write_timeout_usec),
|
||||
read_buff_(read_buff_size_, 0) {}
|
||||
|
||||
inline SocketStream::~SocketStream() {}
|
||||
inline SocketStream::~SocketStream() = default;
|
||||
|
||||
inline bool SocketStream::is_readable() const {
|
||||
return select_read(sock_, read_timeout_sec_, read_timeout_usec_) > 0;
|
||||
@@ -5897,7 +5917,7 @@ inline Server::Server()
|
||||
#endif
|
||||
}
|
||||
|
||||
inline Server::~Server() {}
|
||||
inline Server::~Server() = default;
|
||||
|
||||
inline std::unique_ptr<detail::MatcherBase>
|
||||
Server::make_matcher(const std::string &pattern) {
|
||||
@@ -5909,66 +5929,60 @@ Server::make_matcher(const std::string &pattern) {
|
||||
}
|
||||
|
||||
inline Server &Server::Get(const std::string &pattern, Handler handler) {
|
||||
get_handlers_.push_back(
|
||||
std::make_pair(make_matcher(pattern), std::move(handler)));
|
||||
get_handlers_.emplace_back(make_matcher(pattern), std::move(handler));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Server &Server::Post(const std::string &pattern, Handler handler) {
|
||||
post_handlers_.push_back(
|
||||
std::make_pair(make_matcher(pattern), std::move(handler)));
|
||||
post_handlers_.emplace_back(make_matcher(pattern), std::move(handler));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Server &Server::Post(const std::string &pattern,
|
||||
HandlerWithContentReader handler) {
|
||||
post_handlers_for_content_reader_.push_back(
|
||||
std::make_pair(make_matcher(pattern), std::move(handler)));
|
||||
post_handlers_for_content_reader_.emplace_back(make_matcher(pattern),
|
||||
std::move(handler));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Server &Server::Put(const std::string &pattern, Handler handler) {
|
||||
put_handlers_.push_back(
|
||||
std::make_pair(make_matcher(pattern), std::move(handler)));
|
||||
put_handlers_.emplace_back(make_matcher(pattern), std::move(handler));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Server &Server::Put(const std::string &pattern,
|
||||
HandlerWithContentReader handler) {
|
||||
put_handlers_for_content_reader_.push_back(
|
||||
std::make_pair(make_matcher(pattern), std::move(handler)));
|
||||
put_handlers_for_content_reader_.emplace_back(make_matcher(pattern),
|
||||
std::move(handler));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Server &Server::Patch(const std::string &pattern, Handler handler) {
|
||||
patch_handlers_.push_back(
|
||||
std::make_pair(make_matcher(pattern), std::move(handler)));
|
||||
patch_handlers_.emplace_back(make_matcher(pattern), std::move(handler));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Server &Server::Patch(const std::string &pattern,
|
||||
HandlerWithContentReader handler) {
|
||||
patch_handlers_for_content_reader_.push_back(
|
||||
std::make_pair(make_matcher(pattern), std::move(handler)));
|
||||
patch_handlers_for_content_reader_.emplace_back(make_matcher(pattern),
|
||||
std::move(handler));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Server &Server::Delete(const std::string &pattern, Handler handler) {
|
||||
delete_handlers_.push_back(
|
||||
std::make_pair(make_matcher(pattern), std::move(handler)));
|
||||
delete_handlers_.emplace_back(make_matcher(pattern), std::move(handler));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Server &Server::Delete(const std::string &pattern,
|
||||
HandlerWithContentReader handler) {
|
||||
delete_handlers_for_content_reader_.push_back(
|
||||
std::make_pair(make_matcher(pattern), std::move(handler)));
|
||||
delete_handlers_for_content_reader_.emplace_back(make_matcher(pattern),
|
||||
std::move(handler));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Server &Server::Options(const std::string &pattern, Handler handler) {
|
||||
options_handlers_.push_back(
|
||||
std::make_pair(make_matcher(pattern), std::move(handler)));
|
||||
options_handlers_.emplace_back(make_matcher(pattern), std::move(handler));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -6116,9 +6130,7 @@ inline Server &Server::set_payload_max_length(size_t length) {
|
||||
|
||||
inline bool Server::bind_to_port(const std::string &host, int port,
|
||||
int socket_flags) {
|
||||
if (bind_internal(host, port, socket_flags) < 0)
|
||||
return false;
|
||||
return true;
|
||||
return bind_internal(host, port, socket_flags) >= 0;
|
||||
}
|
||||
inline int Server::bind_to_any_port(const std::string &host, int socket_flags) {
|
||||
return bind_internal(host, 0, socket_flags);
|
||||
@@ -6152,7 +6164,7 @@ inline void Server::stop() {
|
||||
}
|
||||
}
|
||||
|
||||
inline bool Server::parse_request_line(const char *s, Request &req) {
|
||||
inline bool Server::parse_request_line(const char *s, Request &req) const {
|
||||
auto len = strlen(s);
|
||||
if (len < 2 || s[len - 2] != '\r' || s[len - 1] != '\n') {
|
||||
return false;
|
||||
@@ -6208,7 +6220,7 @@ inline bool Server::parse_request_line(const char *s, Request &req) {
|
||||
size_t count = 0;
|
||||
|
||||
detail::split(req.target.data(), req.target.data() + req.target.size(), '?',
|
||||
[&](const char *b, const char *e) {
|
||||
2, [&](const char *b, const char *e) {
|
||||
switch (count) {
|
||||
case 0:
|
||||
req.path = detail::decode_url(std::string(b, e), false);
|
||||
@@ -6433,10 +6445,11 @@ inline bool Server::read_content_with_content_receiver(
|
||||
std::move(multipart_receiver));
|
||||
}
|
||||
|
||||
inline bool Server::read_content_core(Stream &strm, Request &req, Response &res,
|
||||
ContentReceiver receiver,
|
||||
MultipartContentHeader multipart_header,
|
||||
ContentReceiver multipart_receiver) {
|
||||
inline bool
|
||||
Server::read_content_core(Stream &strm, Request &req, Response &res,
|
||||
ContentReceiver receiver,
|
||||
MultipartContentHeader multipart_header,
|
||||
ContentReceiver multipart_receiver) const {
|
||||
detail::MultipartFormDataParser multipart_form_data_parser;
|
||||
ContentReceiverWithProgress out;
|
||||
|
||||
@@ -6502,7 +6515,7 @@ inline bool Server::handle_file_request(const Request &req, Response &res,
|
||||
|
||||
if (detail::is_file(path)) {
|
||||
for (const auto &kv : entry.headers) {
|
||||
res.set_header(kv.first.c_str(), kv.second);
|
||||
res.set_header(kv.first, kv.second);
|
||||
}
|
||||
|
||||
auto mm = std::make_shared<detail::mmap>(path.c_str());
|
||||
@@ -6739,7 +6752,7 @@ inline bool Server::routing(Request &req, Response &res, Stream &strm) {
|
||||
}
|
||||
|
||||
inline bool Server::dispatch_request(Request &req, Response &res,
|
||||
const Handlers &handlers) {
|
||||
const Handlers &handlers) const {
|
||||
for (const auto &x : handlers) {
|
||||
const auto &matcher = x.first;
|
||||
const auto &handler = x.second;
|
||||
@@ -6754,7 +6767,7 @@ inline bool Server::dispatch_request(Request &req, Response &res,
|
||||
|
||||
inline void Server::apply_ranges(const Request &req, Response &res,
|
||||
std::string &content_type,
|
||||
std::string &boundary) {
|
||||
std::string &boundary) const {
|
||||
if (req.ranges.size() > 1) {
|
||||
boundary = detail::make_multipart_data_boundary();
|
||||
|
||||
@@ -6866,7 +6879,7 @@ inline void Server::apply_ranges(const Request &req, Response &res,
|
||||
|
||||
inline bool Server::dispatch_request_for_content_reader(
|
||||
Request &req, Response &res, ContentReader content_reader,
|
||||
const HandlersForContentReader &handlers) {
|
||||
const HandlersForContentReader &handlers) const {
|
||||
for (const auto &x : handlers) {
|
||||
const auto &matcher = x.first;
|
||||
const auto &handler = x.second;
|
||||
@@ -7125,8 +7138,9 @@ inline socket_t ClientImpl::create_client_socket(Error &error) const {
|
||||
// Check is custom IP specified for host_
|
||||
std::string ip;
|
||||
auto it = addr_map_.find(host_);
|
||||
if (it != addr_map_.end())
|
||||
if (it != addr_map_.end()) {
|
||||
ip = it->second;
|
||||
}
|
||||
|
||||
return detail::create_client_socket(
|
||||
host_, ip, port_, address_family_, tcp_nodelay_, socket_options_,
|
||||
@@ -7153,7 +7167,7 @@ inline void ClientImpl::shutdown_ssl(Socket & /*socket*/,
|
||||
socket_requests_are_from_thread_ == std::this_thread::get_id());
|
||||
}
|
||||
|
||||
inline void ClientImpl::shutdown_socket(Socket &socket) {
|
||||
inline void ClientImpl::shutdown_socket(Socket &socket) const {
|
||||
if (socket.sock == INVALID_SOCKET) {
|
||||
return;
|
||||
}
|
||||
@@ -7182,7 +7196,7 @@ inline void ClientImpl::close_socket(Socket &socket) {
|
||||
}
|
||||
|
||||
inline bool ClientImpl::read_response_line(Stream &strm, const Request &req,
|
||||
Response &res) {
|
||||
Response &res) const {
|
||||
std::array<char, 2048> buf{};
|
||||
|
||||
detail::stream_line_reader line_reader(strm, buf.data(), buf.size());
|
||||
@@ -7476,7 +7490,7 @@ inline bool ClientImpl::redirect(Request &req, Response &res, Error &error) {
|
||||
} else {
|
||||
if (next_scheme == "https") {
|
||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
SSLClient cli(next_host.c_str(), next_port);
|
||||
SSLClient cli(next_host, next_port);
|
||||
cli.copy_settings(*this);
|
||||
if (ca_cert_store_) {
|
||||
cli.set_ca_cert_store(ca_cert_store_);
|
||||
@@ -7486,7 +7500,7 @@ inline bool ClientImpl::redirect(Request &req, Response &res, Error &error) {
|
||||
return false;
|
||||
#endif
|
||||
} else {
|
||||
ClientImpl cli(next_host.c_str(), next_port);
|
||||
ClientImpl cli(next_host, next_port);
|
||||
cli.copy_settings(*this);
|
||||
return detail::redirect(cli, req, res, path, location, error);
|
||||
}
|
||||
@@ -7495,7 +7509,7 @@ inline bool ClientImpl::redirect(Request &req, Response &res, Error &error) {
|
||||
|
||||
inline bool ClientImpl::write_content_with_provider(Stream &strm,
|
||||
const Request &req,
|
||||
Error &error) {
|
||||
Error &error) const {
|
||||
auto is_shutting_down = []() { return false; };
|
||||
|
||||
if (req.is_chunked_content_provider_) {
|
||||
@@ -7843,13 +7857,14 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req,
|
||||
|
||||
inline ContentProviderWithoutLength ClientImpl::get_multipart_content_provider(
|
||||
const std::string &boundary, const MultipartFormDataItems &items,
|
||||
const MultipartFormDataProviderItems &provider_items) {
|
||||
size_t cur_item = 0, cur_start = 0;
|
||||
const MultipartFormDataProviderItems &provider_items) const {
|
||||
size_t cur_item = 0;
|
||||
size_t cur_start = 0;
|
||||
// cur_item and cur_start are copied to within the std::function and maintain
|
||||
// state between successive calls
|
||||
return [&, cur_item, cur_start](size_t offset,
|
||||
DataSink &sink) mutable -> bool {
|
||||
if (!offset && items.size()) {
|
||||
if (!offset && !items.empty()) {
|
||||
sink.os << detail::serialize_multipart_formdata(items, boundary, false);
|
||||
return true;
|
||||
} else if (cur_item < provider_items.size()) {
|
||||
@@ -7866,8 +7881,9 @@ inline ContentProviderWithoutLength ClientImpl::get_multipart_content_provider(
|
||||
cur_sink.write = sink.write;
|
||||
cur_sink.done = [&]() { has_data = false; };
|
||||
|
||||
if (!provider_items[cur_item].provider(offset - cur_start, cur_sink))
|
||||
if (!provider_items[cur_item].provider(offset - cur_start, cur_sink)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!has_data) {
|
||||
sink.os << detail::serialize_multipart_formdata_item_end();
|
||||
@@ -7988,7 +8004,7 @@ inline Result ClientImpl::Get(const std::string &path, const Params ¶ms,
|
||||
}
|
||||
|
||||
std::string path_with_query = append_query_params(path, params);
|
||||
return Get(path_with_query.c_str(), headers, progress);
|
||||
return Get(path_with_query, headers, progress);
|
||||
}
|
||||
|
||||
inline Result ClientImpl::Get(const std::string &path, const Params ¶ms,
|
||||
@@ -8008,8 +8024,8 @@ inline Result ClientImpl::Get(const std::string &path, const Params ¶ms,
|
||||
}
|
||||
|
||||
std::string path_with_query = append_query_params(path, params);
|
||||
return Get(path_with_query.c_str(), headers, response_handler,
|
||||
content_receiver, progress);
|
||||
return Get(path_with_query, headers, response_handler, content_receiver,
|
||||
progress);
|
||||
}
|
||||
|
||||
inline Result ClientImpl::Head(const std::string &path) {
|
||||
@@ -8111,7 +8127,7 @@ inline Result ClientImpl::Post(const std::string &path, const Headers &headers,
|
||||
const auto &content_type =
|
||||
detail::serialize_multipart_formdata_get_content_type(boundary);
|
||||
const auto &body = detail::serialize_multipart_formdata(items, boundary);
|
||||
return Post(path, headers, body, content_type.c_str());
|
||||
return Post(path, headers, body, content_type);
|
||||
}
|
||||
|
||||
inline Result ClientImpl::Post(const std::string &path, const Headers &headers,
|
||||
@@ -8124,7 +8140,7 @@ inline Result ClientImpl::Post(const std::string &path, const Headers &headers,
|
||||
const auto &content_type =
|
||||
detail::serialize_multipart_formdata_get_content_type(boundary);
|
||||
const auto &body = detail::serialize_multipart_formdata(items, boundary);
|
||||
return Post(path, headers, body, content_type.c_str());
|
||||
return Post(path, headers, body, content_type);
|
||||
}
|
||||
|
||||
inline Result
|
||||
@@ -8508,10 +8524,11 @@ inline void ClientImpl::set_ca_cert_store(X509_STORE *ca_cert_store) {
|
||||
}
|
||||
|
||||
inline X509_STORE *ClientImpl::create_ca_cert_store(const char *ca_cert,
|
||||
std::size_t size) {
|
||||
std::size_t size) const {
|
||||
auto mem = BIO_new_mem_buf(ca_cert, static_cast<int>(size));
|
||||
if (!mem)
|
||||
if (!mem) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto inf = PEM_X509_INFO_read_bio(mem, nullptr, nullptr, nullptr);
|
||||
if (!inf) {
|
||||
@@ -8676,7 +8693,7 @@ inline SSLSocketStream::SSLSocketStream(socket_t sock, SSL *ssl,
|
||||
SSL_clear_mode(ssl, SSL_MODE_AUTO_RETRY);
|
||||
}
|
||||
|
||||
inline SSLSocketStream::~SSLSocketStream() {}
|
||||
inline SSLSocketStream::~SSLSocketStream() = default;
|
||||
|
||||
inline bool SSLSocketStream::is_readable() const {
|
||||
return detail::select_read(sock_, read_timeout_sec_, read_timeout_usec_) > 0;
|
||||
@@ -8898,7 +8915,7 @@ inline SSLClient::SSLClient(const std::string &host, int port,
|
||||
|
||||
detail::split(&host_[0], &host_[host_.size()], '.',
|
||||
[&](const char *b, const char *e) {
|
||||
host_components_.emplace_back(std::string(b, e));
|
||||
host_components_.emplace_back(b, e);
|
||||
});
|
||||
|
||||
if (!client_cert_path.empty() && !client_key_path.empty()) {
|
||||
@@ -8919,7 +8936,7 @@ inline SSLClient::SSLClient(const std::string &host, int port,
|
||||
|
||||
detail::split(&host_[0], &host_[host_.size()], '.',
|
||||
[&](const char *b, const char *e) {
|
||||
host_components_.emplace_back(std::string(b, e));
|
||||
host_components_.emplace_back(b, e);
|
||||
});
|
||||
|
||||
if (client_cert != nullptr && client_key != nullptr) {
|
||||
@@ -9197,8 +9214,8 @@ SSLClient::verify_host_with_subject_alt_name(X509 *server_cert) const {
|
||||
|
||||
auto type = GEN_DNS;
|
||||
|
||||
struct in6_addr addr6;
|
||||
struct in_addr addr;
|
||||
struct in6_addr addr6 {};
|
||||
struct in_addr addr {};
|
||||
size_t addr_len = 0;
|
||||
|
||||
#ifndef __MINGW32__
|
||||
@@ -9279,7 +9296,7 @@ inline bool SSLClient::check_host_name(const char *pattern,
|
||||
std::vector<std::string> pattern_components;
|
||||
detail::split(&pattern[0], &pattern[pattern_len], '.',
|
||||
[&](const char *b, const char *e) {
|
||||
pattern_components.emplace_back(std::string(b, e));
|
||||
pattern_components.emplace_back(b, e);
|
||||
});
|
||||
|
||||
if (host_components_.size() != pattern_components.size()) {
|
||||
@@ -9364,7 +9381,7 @@ inline Client::Client(const std::string &host, int port,
|
||||
: cli_(detail::make_unique<ClientImpl>(host, port, client_cert_path,
|
||||
client_key_path)) {}
|
||||
|
||||
inline Client::~Client() {}
|
||||
inline Client::~Client() = default;
|
||||
|
||||
inline bool Client::is_valid() const {
|
||||
return cli_ != nullptr && cli_->is_valid();
|
||||
|
Reference in New Issue
Block a user