Skip to content

Commit

Permalink
update libs
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroAir committed Oct 19, 2023
1 parent add5a4c commit 9d0de7b
Show file tree
Hide file tree
Showing 10 changed files with 2,820 additions and 1,087 deletions.
21 changes: 21 additions & 0 deletions libs/LICENSE.EMHASH8
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 hyb

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1,515 changes: 917 additions & 598 deletions libs/cimg/CImg.h

Large diffs are not rendered by default.

28 changes: 22 additions & 6 deletions libs/cpp_httplib/httplib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,7 @@ bool read_content(Stream &strm, T &x, size_t payload_max_length, int &status,
} else if (!has_header(x.headers, "Content-Length")) {
ret = read_content_without_length(strm, out);
} else {
auto len = get_header_value<uint64_t>(x.headers, "Content-Length");
auto len = get_header_value_u64(x.headers, "Content-Length", 0, 0);
if (len > payload_max_length) {
exceed_payload_max_length = true;
skip_content_with_length(strm, len);
Expand Down Expand Up @@ -2815,7 +2815,7 @@ bool parse_www_authenticate(const Response &res,
s = s.substr(pos + 1);
auto beg = std::sregex_iterator(s.begin(), s.end(), re);
for (auto i = beg; i != std::sregex_iterator(); ++i) {
auto m = *i;
const auto &m = *i;
auto key = s.substr(static_cast<size_t>(m.position(1)),
static_cast<size_t>(m.length(1)));
auto val = m.length(2) > 0
Expand Down Expand Up @@ -3510,6 +3510,12 @@ Server &Server::set_default_headers(Headers headers) {
return *this;
}

Server &Server::set_header_writer(
std::function<ssize_t(Stream &, Headers &)> const &writer) {
header_writer_ = writer;
return *this;
}

Server &Server::set_keep_alive_max_count(size_t count) {
keep_alive_max_count_ = count;
return *this;
Expand Down Expand Up @@ -3704,7 +3710,7 @@ bool Server::write_response_core(Stream &strm, bool close_connection,
return false;
}

if (!detail::write_headers(bstrm, res.headers)) { return false; }
if (!header_writer_(bstrm, res.headers)) { return false; }

// Flush buffer
auto &data = bstrm.get_buffer();
Expand Down Expand Up @@ -4552,9 +4558,9 @@ bool ClientImpl::read_response_line(Stream &strm, const Request &req,
if (!line_reader.getline()) { return false; }

#ifdef CPPHTTPLIB_ALLOW_LF_AS_LINE_TERMINATOR
const static std::regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r\n");
#else
const static std::regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r?\n");
#else
const static std::regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r\n");
#endif

std::cmatch m;
Expand Down Expand Up @@ -4943,7 +4949,7 @@ bool ClientImpl::write_request(Stream &strm, Request &req,
const auto &path = url_encode_ ? detail::encode_url(req.path) : req.path;
bstrm.write_format("%s %s HTTP/1.1\r\n", req.method.c_str(), path.c_str());

detail::write_headers(bstrm, req.headers);
header_writer_(bstrm, req.headers);

// Flush buffer
auto &data = bstrm.get_buffer();
Expand Down Expand Up @@ -5754,6 +5760,11 @@ void ClientImpl::set_default_headers(Headers headers) {
default_headers_ = std::move(headers);
}

void ClientImpl::set_header_writer(
std::function<ssize_t(Stream &, Headers &)> const &writer) {
header_writer_ = writer;
}

void ClientImpl::set_address_family(int family) {
address_family_ = family;
}
Expand Down Expand Up @@ -6948,6 +6959,11 @@ void Client::set_default_headers(Headers headers) {
cli_->set_default_headers(std::move(headers));
}

void Client::set_header_writer(
std::function<ssize_t(Stream &, Headers &)> const &writer) {
cli_->set_header_writer(writer);
}

void Client::set_address_family(int family) {
cli_->set_address_family(family);
}
Expand Down
61 changes: 34 additions & 27 deletions libs/cpp_httplib/httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef CPPHTTPLIB_HTTPLIB_H
#define CPPHTTPLIB_HTTPLIB_H

#define CPPHTTPLIB_VERSION "0.13.3"
#define CPPHTTPLIB_VERSION "0.14.1"

/*
* Configuration
Expand Down Expand Up @@ -233,7 +233,7 @@ using socket_t = int;
#include <unordered_map>
#include <unordered_set>
#include <utility>
#define CPPHTTPLIB_OPENSSL_SUPPORT

#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
#ifdef _WIN32
#include <wincrypt.h>
Expand Down Expand Up @@ -487,8 +487,7 @@ struct Request {

bool has_header(const std::string &key) const;
std::string get_header_value(const std::string &key, size_t id = 0) const;
template <typename T>
T get_header_value(const std::string &key, size_t id = 0) const;
uint64_t get_header_value_u64(const std::string &key, size_t id = 0) const;
size_t get_header_value_count(const std::string &key) const;
void set_header(const std::string &key, const std::string &val);

Expand Down Expand Up @@ -520,8 +519,7 @@ struct Response {

bool has_header(const std::string &key) const;
std::string get_header_value(const std::string &key, size_t id = 0) const;
template <typename T>
T get_header_value(const std::string &key, size_t id = 0) const;
uint64_t get_header_value_u64(const std::string &key, size_t id = 0) const;
size_t get_header_value_count(const std::string &key) const;
void set_header(const std::string &key, const std::string &val);

Expand Down Expand Up @@ -739,6 +737,8 @@ class RegexMatcher : public MatcherBase {
std::regex regex_;
};

ssize_t write_headers(Stream &strm, const Headers &headers);

} // namespace detail

class Server {
Expand Down Expand Up @@ -802,6 +802,8 @@ class Server {
Server &set_socket_options(SocketOptions socket_options);

Server &set_default_headers(Headers headers);
Server &
set_header_writer(std::function<ssize_t(Stream &, Headers &)> const &writer);

Server &set_keep_alive_max_count(size_t count);
Server &set_keep_alive_timeout(time_t sec);
Expand Down Expand Up @@ -936,6 +938,8 @@ class Server {
SocketOptions socket_options_ = default_socket_options;

Headers default_headers_;
std::function<ssize_t(Stream &, Headers &)> header_writer_ =
detail::write_headers;
};

enum class Error {
Expand Down Expand Up @@ -988,8 +992,8 @@ class Result {
bool has_request_header(const std::string &key) const;
std::string get_request_header_value(const std::string &key,
size_t id = 0) const;
template <typename T>
T get_request_header_value(const std::string &key, size_t id = 0) const;
uint64_t get_request_header_value_u64(const std::string &key,
size_t id = 0) const;
size_t get_request_header_value_count(const std::string &key) const;

private:
Expand Down Expand Up @@ -1166,6 +1170,9 @@ class ClientImpl {

void set_default_headers(Headers headers);

void
set_header_writer(std::function<ssize_t(Stream &, Headers &)> const &writer);

void set_address_family(int family);
void set_tcp_nodelay(bool on);
void set_socket_options(SocketOptions socket_options);
Expand Down Expand Up @@ -1275,6 +1282,10 @@ class ClientImpl {
// Default headers
Headers default_headers_;

// Header writer
std::function<ssize_t(Stream &, Headers &)> header_writer_ =
detail::write_headers;

// Settings
std::string client_cert_path_;
std::string client_key_path_;
Expand Down Expand Up @@ -1541,6 +1552,9 @@ class Client {

void set_default_headers(Headers headers);

void
set_header_writer(std::function<ssize_t(Stream &, Headers &)> const &writer);

void set_address_family(int family);
void set_tcp_nodelay(bool on);
void set_socket_options(SocketOptions socket_options);
Expand Down Expand Up @@ -1710,15 +1724,9 @@ inline void duration_to_sec_and_usec(const T &duration, U callback) {
callback(static_cast<time_t>(sec), static_cast<time_t>(usec));
}

template <typename T>
inline T get_header_value(const Headers & /*headers*/,
const std::string & /*key*/, size_t /*id*/ = 0,
uint64_t /*def*/ = 0) {}

template <>
inline uint64_t get_header_value<uint64_t>(const Headers &headers,
const std::string &key, size_t id,
uint64_t def) {
inline uint64_t get_header_value_u64(const Headers &headers,
const std::string &key, size_t id,
uint64_t def) {
auto rng = headers.equal_range(key);
auto it = rng.first;
std::advance(it, static_cast<ssize_t>(id));
Expand All @@ -1730,14 +1738,14 @@ inline uint64_t get_header_value<uint64_t>(const Headers &headers,

} // namespace detail

template <typename T>
inline T Request::get_header_value(const std::string &key, size_t id) const {
return detail::get_header_value<T>(headers, key, id, 0);
inline uint64_t Request::get_header_value_u64(const std::string &key,
size_t id) const {
return detail::get_header_value_u64(headers, key, id, 0);
}

template <typename T>
inline T Response::get_header_value(const std::string &key, size_t id) const {
return detail::get_header_value<T>(headers, key, id, 0);
inline uint64_t Response::get_header_value_u64(const std::string &key,
size_t id) const {
return detail::get_header_value_u64(headers, key, id, 0);
}

template <typename... Args>
Expand Down Expand Up @@ -1906,10 +1914,9 @@ inline std::ostream &operator<<(std::ostream &os, const Error &obj) {
return os;
}

template <typename T>
inline T Result::get_request_header_value(const std::string &key,
size_t id) const {
return detail::get_header_value<T>(request_headers_, key, id, 0);
inline uint64_t Result::get_request_header_value_u64(const std::string &key,
size_t id) const {
return detail::get_header_value_u64(request_headers_, key, id, 0);
}

template <class Rep, class Period>
Expand Down
Loading

0 comments on commit 9d0de7b

Please sign in to comment.