vendor : update cpp-httplib to 0.34.0 (#19830)
Signed-off-by: Adrien Gallouët <angt@huggingface.co>
This commit is contained in:
parent
d8aeb65cee
commit
b68a83e641
3 changed files with 80 additions and 35 deletions
|
|
@ -5,7 +5,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
HTTPLIB_VERSION = "refs/tags/v0.33.1"
|
HTTPLIB_VERSION = "refs/tags/v0.34.0"
|
||||||
|
|
||||||
vendor = {
|
vendor = {
|
||||||
"https://github.com/nlohmann/json/releases/latest/download/json.hpp": "vendor/nlohmann/json.hpp",
|
"https://github.com/nlohmann/json/releases/latest/download/json.hpp": "vendor/nlohmann/json.hpp",
|
||||||
|
|
|
||||||
82
vendor/cpp-httplib/httplib.cpp
vendored
82
vendor/cpp-httplib/httplib.cpp
vendored
|
|
@ -1660,6 +1660,7 @@ public:
|
||||||
bool is_readable() const override;
|
bool is_readable() const override;
|
||||||
bool wait_readable() const override;
|
bool wait_readable() const override;
|
||||||
bool wait_writable() const override;
|
bool wait_writable() const override;
|
||||||
|
bool is_peer_alive() const override;
|
||||||
ssize_t read(char *ptr, size_t size) override;
|
ssize_t read(char *ptr, size_t size) override;
|
||||||
ssize_t write(const char *ptr, size_t size) override;
|
ssize_t write(const char *ptr, size_t size) override;
|
||||||
void get_remote_ip_and_port(std::string &ip, int &port) const override;
|
void get_remote_ip_and_port(std::string &ip, int &port) const override;
|
||||||
|
|
@ -3313,10 +3314,10 @@ bool write_content_with_progress(Stream &strm,
|
||||||
return ok;
|
return ok;
|
||||||
};
|
};
|
||||||
|
|
||||||
data_sink.is_writable = [&]() -> bool { return strm.wait_writable(); };
|
data_sink.is_writable = [&]() -> bool { return strm.is_peer_alive(); };
|
||||||
|
|
||||||
while (offset < end_offset && !is_shutting_down()) {
|
while (offset < end_offset && !is_shutting_down()) {
|
||||||
if (!strm.wait_writable()) {
|
if (!strm.wait_writable() || !strm.is_peer_alive()) {
|
||||||
error = Error::Write;
|
error = Error::Write;
|
||||||
return false;
|
return false;
|
||||||
} else if (!content_provider(offset, end_offset - offset, data_sink)) {
|
} else if (!content_provider(offset, end_offset - offset, data_sink)) {
|
||||||
|
|
@ -3328,6 +3329,11 @@ bool write_content_with_progress(Stream &strm,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (offset < end_offset) { // exited due to is_shutting_down(), not completion
|
||||||
|
error = Error::Write;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
error = Error::Success;
|
error = Error::Success;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -3367,12 +3373,12 @@ write_content_without_length(Stream &strm,
|
||||||
return ok;
|
return ok;
|
||||||
};
|
};
|
||||||
|
|
||||||
data_sink.is_writable = [&]() -> bool { return strm.wait_writable(); };
|
data_sink.is_writable = [&]() -> bool { return strm.is_peer_alive(); };
|
||||||
|
|
||||||
data_sink.done = [&](void) { data_available = false; };
|
data_sink.done = [&](void) { data_available = false; };
|
||||||
|
|
||||||
while (data_available && !is_shutting_down()) {
|
while (data_available && !is_shutting_down()) {
|
||||||
if (!strm.wait_writable()) {
|
if (!strm.wait_writable() || !strm.is_peer_alive()) {
|
||||||
return false;
|
return false;
|
||||||
} else if (!content_provider(offset, 0, data_sink)) {
|
} else if (!content_provider(offset, 0, data_sink)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -3380,7 +3386,8 @@ write_content_without_length(Stream &strm,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return !data_available; // true only if done() was called, false if shutting
|
||||||
|
// down
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
|
|
@ -3416,7 +3423,7 @@ write_content_chunked(Stream &strm, const ContentProvider &content_provider,
|
||||||
return ok;
|
return ok;
|
||||||
};
|
};
|
||||||
|
|
||||||
data_sink.is_writable = [&]() -> bool { return strm.wait_writable(); };
|
data_sink.is_writable = [&]() -> bool { return strm.is_peer_alive(); };
|
||||||
|
|
||||||
auto done_with_trailer = [&](const Headers *trailer) {
|
auto done_with_trailer = [&](const Headers *trailer) {
|
||||||
if (!ok) { return; }
|
if (!ok) { return; }
|
||||||
|
|
@ -3466,7 +3473,7 @@ write_content_chunked(Stream &strm, const ContentProvider &content_provider,
|
||||||
};
|
};
|
||||||
|
|
||||||
while (data_available && !is_shutting_down()) {
|
while (data_available && !is_shutting_down()) {
|
||||||
if (!strm.wait_writable()) {
|
if (!strm.wait_writable() || !strm.is_peer_alive()) {
|
||||||
error = Error::Write;
|
error = Error::Write;
|
||||||
return false;
|
return false;
|
||||||
} else if (!content_provider(offset, 0, data_sink)) {
|
} else if (!content_provider(offset, 0, data_sink)) {
|
||||||
|
|
@ -3478,6 +3485,11 @@ write_content_chunked(Stream &strm, const ContentProvider &content_provider,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data_available) { // exited due to is_shutting_down(), not done()
|
||||||
|
error = Error::Write;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
error = Error::Success;
|
error = Error::Success;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -4646,6 +4658,7 @@ public:
|
||||||
bool is_readable() const override;
|
bool is_readable() const override;
|
||||||
bool wait_readable() const override;
|
bool wait_readable() const override;
|
||||||
bool wait_writable() const override;
|
bool wait_writable() const override;
|
||||||
|
bool is_peer_alive() const override;
|
||||||
ssize_t read(char *ptr, size_t size) override;
|
ssize_t read(char *ptr, size_t size) override;
|
||||||
ssize_t write(const char *ptr, size_t size) override;
|
ssize_t write(const char *ptr, size_t size) override;
|
||||||
void get_remote_ip_and_port(std::string &ip, int &port) const override;
|
void get_remote_ip_and_port(std::string &ip, int &port) const override;
|
||||||
|
|
@ -6069,8 +6082,11 @@ bool SocketStream::wait_readable() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SocketStream::wait_writable() const {
|
bool SocketStream::wait_writable() const {
|
||||||
return select_write(sock_, write_timeout_sec_, write_timeout_usec_) > 0 &&
|
return select_write(sock_, write_timeout_sec_, write_timeout_usec_) > 0;
|
||||||
is_socket_alive(sock_);
|
}
|
||||||
|
|
||||||
|
bool SocketStream::is_peer_alive() const {
|
||||||
|
return detail::is_socket_alive(sock_);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t SocketStream::read(char *ptr, size_t size) {
|
ssize_t SocketStream::read(char *ptr, size_t size) {
|
||||||
|
|
@ -6401,7 +6417,11 @@ bool SSLSocketStream::wait_readable() const {
|
||||||
|
|
||||||
bool SSLSocketStream::wait_writable() const {
|
bool SSLSocketStream::wait_writable() const {
|
||||||
return select_write(sock_, write_timeout_sec_, write_timeout_usec_) > 0 &&
|
return select_write(sock_, write_timeout_sec_, write_timeout_usec_) > 0 &&
|
||||||
is_socket_alive(sock_) && !tls::is_peer_closed(session_, sock_);
|
!tls::is_peer_closed(session_, sock_);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SSLSocketStream::is_peer_alive() const {
|
||||||
|
return !tls::is_peer_closed(session_, sock_);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t SSLSocketStream::read(char *ptr, size_t size) {
|
ssize_t SSLSocketStream::read(char *ptr, size_t size) {
|
||||||
|
|
@ -6925,35 +6945,33 @@ bool Server::write_response_core(Stream &strm, bool close_connection,
|
||||||
if (post_routing_handler_) { post_routing_handler_(req, res); }
|
if (post_routing_handler_) { post_routing_handler_(req, res); }
|
||||||
|
|
||||||
// Response line and headers
|
// Response line and headers
|
||||||
{
|
detail::BufferStream bstrm;
|
||||||
detail::BufferStream bstrm;
|
if (!detail::write_response_line(bstrm, res.status)) { return false; }
|
||||||
if (!detail::write_response_line(bstrm, res.status)) { return false; }
|
if (header_writer_(bstrm, res.headers) <= 0) { return false; }
|
||||||
if (header_writer_(bstrm, res.headers) <= 0) { return false; }
|
|
||||||
|
|
||||||
// Flush buffer
|
// Combine small body with headers to reduce write syscalls
|
||||||
auto &data = bstrm.get_buffer();
|
if (req.method != "HEAD" && !res.body.empty() && !res.content_provider_) {
|
||||||
detail::write_data(strm, data.data(), data.size());
|
bstrm.write(res.body.data(), res.body.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Body
|
// Log before writing to avoid race condition with client-side code that
|
||||||
|
// accesses logger-captured data immediately after receiving the response.
|
||||||
|
output_log(req, res);
|
||||||
|
|
||||||
|
// Flush buffer
|
||||||
|
auto &data = bstrm.get_buffer();
|
||||||
|
if (!detail::write_data(strm, data.data(), data.size())) { return false; }
|
||||||
|
|
||||||
|
// Streaming body
|
||||||
auto ret = true;
|
auto ret = true;
|
||||||
if (req.method != "HEAD") {
|
if (req.method != "HEAD" && res.content_provider_) {
|
||||||
if (!res.body.empty()) {
|
if (write_content_with_provider(strm, req, res, boundary, content_type)) {
|
||||||
if (!detail::write_data(strm, res.body.data(), res.body.size())) {
|
res.content_provider_success_ = true;
|
||||||
ret = false;
|
} else {
|
||||||
}
|
ret = false;
|
||||||
} else if (res.content_provider_) {
|
|
||||||
if (write_content_with_provider(strm, req, res, boundary, content_type)) {
|
|
||||||
res.content_provider_success_ = true;
|
|
||||||
} else {
|
|
||||||
ret = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log
|
|
||||||
output_log(req, res);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
31
vendor/cpp-httplib/httplib.h
vendored
31
vendor/cpp-httplib/httplib.h
vendored
|
|
@ -8,8 +8,8 @@
|
||||||
#ifndef CPPHTTPLIB_HTTPLIB_H
|
#ifndef CPPHTTPLIB_HTTPLIB_H
|
||||||
#define CPPHTTPLIB_HTTPLIB_H
|
#define CPPHTTPLIB_HTTPLIB_H
|
||||||
|
|
||||||
#define CPPHTTPLIB_VERSION "0.33.1"
|
#define CPPHTTPLIB_VERSION "0.34.0"
|
||||||
#define CPPHTTPLIB_VERSION_NUM "0x002101"
|
#define CPPHTTPLIB_VERSION_NUM "0x002200"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Platform compatibility check
|
* Platform compatibility check
|
||||||
|
|
@ -1038,6 +1038,32 @@ make_file_provider(const std::string &name, const std::string &filepath,
|
||||||
return fdp;
|
return fdp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline std::pair<size_t, ContentProvider>
|
||||||
|
make_file_body(const std::string &filepath) {
|
||||||
|
std::ifstream f(filepath, std::ios::binary | std::ios::ate);
|
||||||
|
if (!f) { return {0, ContentProvider{}}; }
|
||||||
|
auto size = static_cast<size_t>(f.tellg());
|
||||||
|
|
||||||
|
ContentProvider provider = [filepath](size_t offset, size_t length,
|
||||||
|
DataSink &sink) -> bool {
|
||||||
|
std::ifstream f(filepath, std::ios::binary);
|
||||||
|
if (!f) { return false; }
|
||||||
|
f.seekg(static_cast<std::streamoff>(offset));
|
||||||
|
if (!f.good()) { return false; }
|
||||||
|
char buf[8192];
|
||||||
|
while (length > 0) {
|
||||||
|
auto to_read = (std::min)(sizeof(buf), length);
|
||||||
|
f.read(buf, static_cast<std::streamsize>(to_read));
|
||||||
|
auto n = static_cast<size_t>(f.gcount());
|
||||||
|
if (n == 0) { break; }
|
||||||
|
if (!sink.write(buf, n)) { return false; }
|
||||||
|
length -= n;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
return {size, std::move(provider)};
|
||||||
|
}
|
||||||
|
|
||||||
using ContentReceiverWithProgress = std::function<bool(
|
using ContentReceiverWithProgress = std::function<bool(
|
||||||
const char *data, size_t data_length, size_t offset, size_t total_length)>;
|
const char *data, size_t data_length, size_t offset, size_t total_length)>;
|
||||||
|
|
||||||
|
|
@ -1352,6 +1378,7 @@ public:
|
||||||
virtual bool is_readable() const = 0;
|
virtual bool is_readable() const = 0;
|
||||||
virtual bool wait_readable() const = 0;
|
virtual bool wait_readable() const = 0;
|
||||||
virtual bool wait_writable() const = 0;
|
virtual bool wait_writable() const = 0;
|
||||||
|
virtual bool is_peer_alive() const { return wait_writable(); }
|
||||||
|
|
||||||
virtual ssize_t read(char *ptr, size_t size) = 0;
|
virtual ssize_t read(char *ptr, size_t size) = 0;
|
||||||
virtual ssize_t write(const char *ptr, size_t size) = 0;
|
virtual ssize_t write(const char *ptr, size_t size) = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue