Cleaner API (breaking change)

This commit is contained in:
yhirose 2024-11-29 17:17:05 -05:00
parent 321a86d9f2
commit 335246bc7d
3 changed files with 262 additions and 515 deletions

515
httplib.h
View file

@ -1241,34 +1241,30 @@ public:
virtual bool is_valid() const;
Result Get(const std::string &path);
Result Get(const std::string &path, const Headers &headers);
Result Get(const std::string &path, Progress progress);
Result Get(const std::string &path, Progress progress = nullptr);
Result Get(const std::string &path, const Headers &headers,
Progress progress);
Result Get(const std::string &path, ContentReceiver content_receiver);
Result Get(const std::string &path, const Headers &headers,
ContentReceiver content_receiver);
Progress progress = nullptr);
Result Get(const std::string &path, ContentReceiver content_receiver,
Progress progress);
Progress progress = nullptr);
Result Get(const std::string &path, const Headers &headers,
ContentReceiver content_receiver, Progress progress);
ContentReceiver content_receiver, Progress progress = nullptr);
Result Get(const std::string &path, ResponseHandler response_handler,
ContentReceiver content_receiver);
Result Get(const std::string &path, const Headers &headers,
ResponseHandler response_handler,
ContentReceiver content_receiver);
Result Get(const std::string &path, ResponseHandler response_handler,
ContentReceiver content_receiver, Progress progress);
ContentReceiver content_receiver, Progress progress = nullptr);
Result Get(const std::string &path, const Headers &headers,
ResponseHandler response_handler, ContentReceiver content_receiver,
Progress progress);
Progress progress = nullptr);
Result Get(const std::string &path, const Params &params,
Progress progres = nullptr);
Result Get(const std::string &path, const Params &params,
const Headers &headers, Progress progress = nullptr);
Result Get(const std::string &path, const Params &params,
ContentReceiver content_receiver, Progress progress = nullptr);
Result Get(const std::string &path, const Params &params,
const Headers &headers, ContentReceiver content_receiver,
Progress progress = nullptr);
Result Get(const std::string &path, const Params &params,
ResponseHandler response_handler, ContentReceiver content_receiver,
Progress progress = nullptr);
Result Get(const std::string &path, const Params &params,
const Headers &headers, ResponseHandler response_handler,
ContentReceiver content_receiver, Progress progress = nullptr);
@ -1280,20 +1276,14 @@ public:
Result Post(const std::string &path, const Headers &headers);
Result Post(const std::string &path, const char *body, size_t content_length,
const std::string &content_type);
Result Post(const std::string &path, const Headers &headers, const char *body,
size_t content_length, const std::string &content_type);
Result Post(const std::string &path, const Headers &headers, const char *body,
size_t content_length, const std::string &content_type,
Progress progress);
Progress progress = nullptr);
Result Post(const std::string &path, const std::string &body,
const std::string &content_type);
Result Post(const std::string &path, const std::string &body,
const std::string &content_type, Progress progress);
Result Post(const std::string &path, const Headers &headers,
const std::string &body, const std::string &content_type);
const std::string &content_type, Progress progress = nullptr);
Result Post(const std::string &path, const Headers &headers,
const std::string &body, const std::string &content_type,
Progress progress);
Progress progress = nullptr);
Result Post(const std::string &path, size_t content_length,
ContentProvider content_provider,
const std::string &content_type);
@ -1308,9 +1298,7 @@ public:
const std::string &content_type);
Result Post(const std::string &path, const Params &params);
Result Post(const std::string &path, const Headers &headers,
const Params &params);
Result Post(const std::string &path, const Headers &headers,
const Params &params, Progress progress);
const Params &params, Progress progress = nullptr);
Result Post(const std::string &path, const MultipartFormDataItems &items);
Result Post(const std::string &path, const Headers &headers,
const MultipartFormDataItems &items);
@ -1323,20 +1311,14 @@ public:
Result Put(const std::string &path);
Result Put(const std::string &path, const char *body, size_t content_length,
const std::string &content_type);
Result Put(const std::string &path, const Headers &headers, const char *body,
size_t content_length, const std::string &content_type);
Result Put(const std::string &path, const Headers &headers, const char *body,
size_t content_length, const std::string &content_type,
Progress progress);
Progress progress = nullptr);
Result Put(const std::string &path, const std::string &body,
const std::string &content_type);
Result Put(const std::string &path, const std::string &body,
const std::string &content_type, Progress progress);
Result Put(const std::string &path, const Headers &headers,
const std::string &body, const std::string &content_type);
const std::string &content_type, Progress progress = nullptr);
Result Put(const std::string &path, const Headers &headers,
const std::string &body, const std::string &content_type,
Progress progress);
Progress progress = nullptr);
Result Put(const std::string &path, size_t content_length,
ContentProvider content_provider, const std::string &content_type);
Result Put(const std::string &path,
@ -1350,9 +1332,7 @@ public:
const std::string &content_type);
Result Put(const std::string &path, const Params &params);
Result Put(const std::string &path, const Headers &headers,
const Params &params);
Result Put(const std::string &path, const Headers &headers,
const Params &params, Progress progress);
const Params &params, Progress progress = nullptr);
Result Put(const std::string &path, const MultipartFormDataItems &items);
Result Put(const std::string &path, const Headers &headers,
const MultipartFormDataItems &items);
@ -1364,24 +1344,15 @@ public:
Result Patch(const std::string &path);
Result Patch(const std::string &path, const char *body, size_t content_length,
const std::string &content_type);
Result Patch(const std::string &path, const char *body, size_t content_length,
const std::string &content_type, Progress progress);
const std::string &content_type, Progress progress = nullptr);
Result Patch(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type);
Result Patch(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type, Progress progress);
const std::string &content_type, Progress progress = nullptr);
Result Patch(const std::string &path, const std::string &body,
const std::string &content_type);
Result Patch(const std::string &path, const std::string &body,
const std::string &content_type, Progress progress);
Result Patch(const std::string &path, const Headers &headers,
const std::string &body, const std::string &content_type);
const std::string &content_type, Progress progress = nullptr);
Result Patch(const std::string &path, const Headers &headers,
const std::string &body, const std::string &content_type,
Progress progress);
Progress progress = nullptr);
Result Patch(const std::string &path, size_t content_length,
ContentProvider content_provider,
const std::string &content_type);
@ -1397,26 +1368,17 @@ public:
Result Delete(const std::string &path);
Result Delete(const std::string &path, const Headers &headers);
Result Delete(const std::string &path, const char *body,
size_t content_length, const std::string &content_type);
Result Delete(const std::string &path, const char *body,
size_t content_length, const std::string &content_type,
Progress progress);
Progress progress = nullptr);
Result Delete(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type);
Result Delete(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type, Progress progress);
const std::string &content_type, Progress progress = nullptr);
Result Delete(const std::string &path, const std::string &body,
const std::string &content_type);
Result Delete(const std::string &path, const std::string &body,
const std::string &content_type, Progress progress);
Result Delete(const std::string &path, const Headers &headers,
const std::string &body, const std::string &content_type);
const std::string &content_type, Progress progress = nullptr);
Result Delete(const std::string &path, const Headers &headers,
const std::string &body, const std::string &content_type,
Progress progress);
Progress progress = nullptr);
Result Options(const std::string &path);
Result Options(const std::string &path, const Headers &headers);
@ -1521,8 +1483,8 @@ protected:
// shutdown_socket
// close_socket
// should ONLY be called when socket_mutex_ is locked.
// Also, shutdown_ssl and close_socket should also NOT be called concurrently
// with a DIFFERENT thread sending requests using that socket.
// 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) const;
void close_socket(Socket &socket);
@ -1680,34 +1642,30 @@ public:
bool is_valid() const;
Result Get(const std::string &path);
Result Get(const std::string &path, const Headers &headers);
Result Get(const std::string &path, Progress progress);
Result Get(const std::string &path, Progress progress = nullptr);
Result Get(const std::string &path, const Headers &headers,
Progress progress);
Result Get(const std::string &path, ContentReceiver content_receiver);
Result Get(const std::string &path, const Headers &headers,
ContentReceiver content_receiver);
Progress progress = nullptr);
Result Get(const std::string &path, ContentReceiver content_receiver,
Progress progress);
Progress progress = nullptr);
Result Get(const std::string &path, const Headers &headers,
ContentReceiver content_receiver, Progress progress);
Result Get(const std::string &path, ResponseHandler response_handler,
ContentReceiver content_receiver);
Result Get(const std::string &path, const Headers &headers,
ResponseHandler response_handler,
ContentReceiver content_receiver);
ContentReceiver content_receiver, Progress progress = nullptr);
Result Get(const std::string &path, const Headers &headers,
ResponseHandler response_handler, ContentReceiver content_receiver,
Progress progress);
Progress progress = nullptr);
Result Get(const std::string &path, ResponseHandler response_handler,
ContentReceiver content_receiver, Progress progress);
ContentReceiver content_receiver, Progress progress = nullptr);
Result Get(const std::string &path, const Params &params,
Progress progress = nullptr);
Result Get(const std::string &path, const Params &params,
const Headers &headers, Progress progress = nullptr);
Result Get(const std::string &path, const Params &params,
ContentReceiver content_receiver, Progress progress = nullptr);
Result Get(const std::string &path, const Params &params,
const Headers &headers, ContentReceiver content_receiver,
Progress progress = nullptr);
Result Get(const std::string &path, const Params &params,
ResponseHandler response_handler, ContentReceiver content_receiver,
Progress progress = nullptr);
Result Get(const std::string &path, const Params &params,
const Headers &headers, ResponseHandler response_handler,
ContentReceiver content_receiver, Progress progress = nullptr);
@ -1719,20 +1677,14 @@ public:
Result Post(const std::string &path, const Headers &headers);
Result Post(const std::string &path, const char *body, size_t content_length,
const std::string &content_type);
Result Post(const std::string &path, const Headers &headers, const char *body,
size_t content_length, const std::string &content_type);
Result Post(const std::string &path, const Headers &headers, const char *body,
size_t content_length, const std::string &content_type,
Progress progress);
Progress progress = nullptr);
Result Post(const std::string &path, const std::string &body,
const std::string &content_type);
Result Post(const std::string &path, const std::string &body,
const std::string &content_type, Progress progress);
Result Post(const std::string &path, const Headers &headers,
const std::string &body, const std::string &content_type);
const std::string &content_type, Progress progress = nullptr);
Result Post(const std::string &path, const Headers &headers,
const std::string &body, const std::string &content_type,
Progress progress);
Progress progress = nullptr);
Result Post(const std::string &path, size_t content_length,
ContentProvider content_provider,
const std::string &content_type);
@ -1747,9 +1699,7 @@ public:
const std::string &content_type);
Result Post(const std::string &path, const Params &params);
Result Post(const std::string &path, const Headers &headers,
const Params &params);
Result Post(const std::string &path, const Headers &headers,
const Params &params, Progress progress);
const Params &params, Progress progress = nullptr);
Result Post(const std::string &path, const MultipartFormDataItems &items);
Result Post(const std::string &path, const Headers &headers,
const MultipartFormDataItems &items);
@ -1762,20 +1712,14 @@ public:
Result Put(const std::string &path);
Result Put(const std::string &path, const char *body, size_t content_length,
const std::string &content_type);
Result Put(const std::string &path, const Headers &headers, const char *body,
size_t content_length, const std::string &content_type);
Result Put(const std::string &path, const Headers &headers, const char *body,
size_t content_length, const std::string &content_type,
Progress progress);
Progress progress = nullptr);
Result Put(const std::string &path, const std::string &body,
const std::string &content_type);
Result Put(const std::string &path, const std::string &body,
const std::string &content_type, Progress progress);
Result Put(const std::string &path, const Headers &headers,
const std::string &body, const std::string &content_type);
const std::string &content_type, Progress progress = nullptr);
Result Put(const std::string &path, const Headers &headers,
const std::string &body, const std::string &content_type,
Progress progress);
Progress progress = nullptr);
Result Put(const std::string &path, size_t content_length,
ContentProvider content_provider, const std::string &content_type);
Result Put(const std::string &path,
@ -1789,9 +1733,7 @@ public:
const std::string &content_type);
Result Put(const std::string &path, const Params &params);
Result Put(const std::string &path, const Headers &headers,
const Params &params);
Result Put(const std::string &path, const Headers &headers,
const Params &params, Progress progress);
const Params &params, Progress progress = nullptr);
Result Put(const std::string &path, const MultipartFormDataItems &items);
Result Put(const std::string &path, const Headers &headers,
const MultipartFormDataItems &items);
@ -1803,24 +1745,15 @@ public:
Result Patch(const std::string &path);
Result Patch(const std::string &path, const char *body, size_t content_length,
const std::string &content_type);
Result Patch(const std::string &path, const char *body, size_t content_length,
const std::string &content_type, Progress progress);
const std::string &content_type, Progress progress = nullptr);
Result Patch(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type);
Result Patch(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type, Progress progress);
const std::string &content_type, Progress progress = nullptr);
Result Patch(const std::string &path, const std::string &body,
const std::string &content_type);
Result Patch(const std::string &path, const std::string &body,
const std::string &content_type, Progress progress);
Result Patch(const std::string &path, const Headers &headers,
const std::string &body, const std::string &content_type);
const std::string &content_type, Progress progress = nullptr);
Result Patch(const std::string &path, const Headers &headers,
const std::string &body, const std::string &content_type,
Progress progress);
Progress progress = nullptr);
Result Patch(const std::string &path, size_t content_length,
ContentProvider content_provider,
const std::string &content_type);
@ -1836,26 +1769,17 @@ public:
Result Delete(const std::string &path);
Result Delete(const std::string &path, const Headers &headers);
Result Delete(const std::string &path, const char *body,
size_t content_length, const std::string &content_type);
Result Delete(const std::string &path, const char *body,
size_t content_length, const std::string &content_type,
Progress progress);
Progress progress = nullptr);
Result Delete(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type);
Result Delete(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type, Progress progress);
const std::string &content_type, Progress progress = nullptr);
Result Delete(const std::string &path, const std::string &body,
const std::string &content_type);
Result Delete(const std::string &path, const std::string &body,
const std::string &content_type, Progress progress);
Result Delete(const std::string &path, const Headers &headers,
const std::string &body, const std::string &content_type);
const std::string &content_type, Progress progress = nullptr);
Result Delete(const std::string &path, const Headers &headers,
const std::string &body, const std::string &content_type,
Progress progress);
Progress progress = nullptr);
Result Options(const std::string &path);
Result Options(const std::string &path, const Headers &headers);
@ -2346,8 +2270,8 @@ Client::set_max_timeout(const std::chrono::duration<Rep, Period> &duration) {
}
/*
* Forward declarations and types that will be part of the .h file if split into
* .h + .cc.
* Forward declarations and types that will be part of the .h file if split
* into .h + .cc.
*/
std::string hosted_at(const std::string &hostname);
@ -3113,8 +3037,8 @@ inline bool mmap::open(const char *path) {
LARGE_INTEGER size{};
if (!::GetFileSizeEx(hFile_, &size)) { return false; }
// If the following line doesn't compile due to QuadPart, update Windows SDK.
// See:
// If the following line doesn't compile due to QuadPart, update Windows
// SDK. See:
// https://github.com/yhirose/cpp-httplib/issues/1903#issuecomment-2316520721
if (static_cast<ULONGLONG>(size.QuadPart) >
(std::numeric_limits<decltype(size_)>::max)()) {
@ -3632,8 +3556,8 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
* https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketa
*
* WSA_FLAG_NO_HANDLE_INHERIT:
* This flag is supported on Windows 7 with SP1, Windows Server 2008 R2 with
* SP1, and later
* This flag is supported on Windows 7 with SP1, Windows Server 2008 R2
* with SP1, and later
*
*/
if (sock == INVALID_SOCKET) {
@ -3885,12 +3809,12 @@ inline constexpr unsigned int str2tag_core(const char *s, size_t l,
unsigned int h) {
return (l == 0)
? h
: str2tag_core(
s + 1, l - 1,
// Unsets the 6 high bits of h, therefore no overflow happens
(((std::numeric_limits<unsigned int>::max)() >> 6) &
h * 33) ^
static_cast<unsigned char>(*s));
: str2tag_core(s + 1, l - 1,
// Unsets the 6 high bits of h, therefore no
// overflow happens
(((std::numeric_limits<unsigned int>::max)() >> 6) &
h * 33) ^
static_cast<unsigned char>(*s));
}
inline unsigned int str2tag(const std::string &s) {
@ -4399,8 +4323,9 @@ inline bool read_content_chunked(Stream &strm, T &x,
// NOTE: In RFC 9112, '7.1 Chunked Transfer Coding' mentions "The chunked
// transfer coding is complete when a chunk with a chunk-size of zero is
// received, possibly followed by a trailer section, and finally terminated by
// an empty line". https://www.rfc-editor.org/rfc/rfc9112.html#section-7.1
// received, possibly followed by a trailer section, and finally terminated
// by an empty line".
// https://www.rfc-editor.org/rfc/rfc9112.html#section-7.1
//
// In '7.1.3. Decoding Chunked', however, the pseudo-code in the section
// does't care for the existence of the final CRLF. In other words, it seems
@ -7573,8 +7498,9 @@ inline bool ClientImpl::send_(Request &req, Response &res, Error &error) {
{
std::lock_guard<std::mutex> guard(socket_mutex_);
// Set this to false immediately - if it ever gets set to true by the end of
// the request, we know another thread instructed us to close the socket.
// Set this to false immediately - if it ever gets set to true by the end
// of the request, we know another thread instructed us to close the
// socket.
socket_should_be_closed_when_request_is_done_ = false;
auto is_alive = false;
@ -8181,8 +8107,8 @@ inline ContentProviderWithoutLength ClientImpl::get_multipart_content_provider(
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
// 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.empty()) {
@ -8231,18 +8157,10 @@ inline bool ClientImpl::process_socket(
inline bool ClientImpl::is_ssl() const { return false; }
inline Result ClientImpl::Get(const std::string &path) {
return Get(path, Headers(), Progress());
}
inline Result ClientImpl::Get(const std::string &path, Progress progress) {
return Get(path, Headers(), std::move(progress));
}
inline Result ClientImpl::Get(const std::string &path, const Headers &headers) {
return Get(path, headers, Progress());
}
inline Result ClientImpl::Get(const std::string &path, const Headers &headers,
Progress progress) {
Request req;
@ -8257,11 +8175,6 @@ inline Result ClientImpl::Get(const std::string &path, const Headers &headers,
return send_(std::move(req));
}
inline Result ClientImpl::Get(const std::string &path,
ContentReceiver content_receiver) {
return Get(path, Headers(), nullptr, std::move(content_receiver), nullptr);
}
inline Result ClientImpl::Get(const std::string &path,
ContentReceiver content_receiver,
Progress progress) {
@ -8269,11 +8182,6 @@ inline Result ClientImpl::Get(const std::string &path,
std::move(progress));
}
inline Result ClientImpl::Get(const std::string &path, const Headers &headers,
ContentReceiver content_receiver) {
return Get(path, headers, nullptr, std::move(content_receiver), nullptr);
}
inline Result ClientImpl::Get(const std::string &path, const Headers &headers,
ContentReceiver content_receiver,
Progress progress) {
@ -8281,20 +8189,6 @@ inline Result ClientImpl::Get(const std::string &path, const Headers &headers,
std::move(progress));
}
inline Result ClientImpl::Get(const std::string &path,
ResponseHandler response_handler,
ContentReceiver content_receiver) {
return Get(path, Headers(), std::move(response_handler),
std::move(content_receiver), nullptr);
}
inline Result ClientImpl::Get(const std::string &path, const Headers &headers,
ResponseHandler response_handler,
ContentReceiver content_receiver) {
return Get(path, headers, std::move(response_handler),
std::move(content_receiver), nullptr);
}
inline Result ClientImpl::Get(const std::string &path,
ResponseHandler response_handler,
ContentReceiver content_receiver,
@ -8325,6 +8219,14 @@ inline Result ClientImpl::Get(const std::string &path, const Headers &headers,
return send_(std::move(req));
}
inline Result ClientImpl::Get(const std::string &path, const Params &params,
Progress progress) {
if (params.empty()) { return Get(path, std::move(progress)); }
std::string path_with_query = append_query_params(path, params);
return Get(path_with_query, std::move(progress));
}
inline Result ClientImpl::Get(const std::string &path, const Params &params,
const Headers &headers, Progress progress) {
if (params.empty()) { return Get(path, headers); }
@ -8333,6 +8235,13 @@ inline Result ClientImpl::Get(const std::string &path, const Params &params,
return Get(path_with_query, headers, std::move(progress));
}
inline Result ClientImpl::Get(const std::string &path, const Params &params,
ContentReceiver content_receiver,
Progress progress) {
return Get(path, params, Headers{}, nullptr, std::move(content_receiver),
std::move(progress));
}
inline Result ClientImpl::Get(const std::string &path, const Params &params,
const Headers &headers,
ContentReceiver content_receiver,
@ -8341,6 +8250,14 @@ inline Result ClientImpl::Get(const std::string &path, const Params &params,
std::move(progress));
}
inline Result ClientImpl::Get(const std::string &path, const Params &params,
ResponseHandler response_handler,
ContentReceiver content_receiver,
Progress progress) {
return Get(path, params, Headers{}, std::move(response_handler),
std::move(content_receiver), std::move(progress));
}
inline Result ClientImpl::Get(const std::string &path, const Params &params,
const Headers &headers,
ResponseHandler response_handler,
@ -8388,13 +8305,6 @@ inline Result ClientImpl::Post(const std::string &path, const char *body,
return Post(path, Headers(), body, content_length, content_type, nullptr);
}
inline Result ClientImpl::Post(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type) {
return send_with_content_provider("POST", path, headers, body, content_length,
nullptr, nullptr, content_type, nullptr);
}
inline Result ClientImpl::Post(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type,
@ -8403,25 +8313,12 @@ inline Result ClientImpl::Post(const std::string &path, const Headers &headers,
nullptr, nullptr, content_type, progress);
}
inline Result ClientImpl::Post(const std::string &path, const std::string &body,
const std::string &content_type) {
return Post(path, Headers(), body, content_type);
}
inline Result ClientImpl::Post(const std::string &path, const std::string &body,
const std::string &content_type,
Progress progress) {
return Post(path, Headers(), body, content_type, progress);
}
inline Result ClientImpl::Post(const std::string &path, const Headers &headers,
const std::string &body,
const std::string &content_type) {
return send_with_content_provider("POST", path, headers, body.data(),
body.size(), nullptr, nullptr, content_type,
nullptr);
}
inline Result ClientImpl::Post(const std::string &path, const Headers &headers,
const std::string &body,
const std::string &content_type,
@ -8465,12 +8362,6 @@ inline Result ClientImpl::Post(const std::string &path, const Headers &headers,
nullptr);
}
inline Result ClientImpl::Post(const std::string &path, const Headers &headers,
const Params &params) {
auto query = detail::params_to_query_str(params);
return Post(path, headers, query, "application/x-www-form-urlencoded");
}
inline Result ClientImpl::Post(const std::string &path, const Headers &headers,
const Params &params, Progress progress) {
auto query = detail::params_to_query_str(params);
@ -8528,13 +8419,6 @@ inline Result ClientImpl::Put(const std::string &path, const char *body,
return Put(path, Headers(), body, content_length, content_type);
}
inline Result ClientImpl::Put(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type) {
return send_with_content_provider("PUT", path, headers, body, content_length,
nullptr, nullptr, content_type, nullptr);
}
inline Result ClientImpl::Put(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type,
@ -8543,25 +8427,12 @@ inline Result ClientImpl::Put(const std::string &path, const Headers &headers,
nullptr, nullptr, content_type, progress);
}
inline Result ClientImpl::Put(const std::string &path, const std::string &body,
const std::string &content_type) {
return Put(path, Headers(), body, content_type);
}
inline Result ClientImpl::Put(const std::string &path, const std::string &body,
const std::string &content_type,
Progress progress) {
return Put(path, Headers(), body, content_type, progress);
}
inline Result ClientImpl::Put(const std::string &path, const Headers &headers,
const std::string &body,
const std::string &content_type) {
return send_with_content_provider("PUT", path, headers, body.data(),
body.size(), nullptr, nullptr, content_type,
nullptr);
}
inline Result ClientImpl::Put(const std::string &path, const Headers &headers,
const std::string &body,
const std::string &content_type,
@ -8605,12 +8476,6 @@ inline Result ClientImpl::Put(const std::string &path, const Params &params) {
return Put(path, Headers(), params);
}
inline Result ClientImpl::Put(const std::string &path, const Headers &headers,
const Params &params) {
auto query = detail::params_to_query_str(params);
return Put(path, headers, query, "application/x-www-form-urlencoded");
}
inline Result ClientImpl::Put(const std::string &path, const Headers &headers,
const Params &params, Progress progress) {
auto query = detail::params_to_query_str(params);
@ -8661,12 +8526,6 @@ inline Result ClientImpl::Patch(const std::string &path) {
return Patch(path, std::string(), std::string());
}
inline Result ClientImpl::Patch(const std::string &path, const char *body,
size_t content_length,
const std::string &content_type) {
return Patch(path, Headers(), body, content_length, content_type);
}
inline Result ClientImpl::Patch(const std::string &path, const char *body,
size_t content_length,
const std::string &content_type,
@ -8674,12 +8533,6 @@ inline Result ClientImpl::Patch(const std::string &path, const char *body,
return Patch(path, Headers(), body, content_length, content_type, progress);
}
inline Result ClientImpl::Patch(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type) {
return Patch(path, headers, body, content_length, content_type, nullptr);
}
inline Result ClientImpl::Patch(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type,
@ -8689,12 +8542,6 @@ inline Result ClientImpl::Patch(const std::string &path, const Headers &headers,
content_type, progress);
}
inline Result ClientImpl::Patch(const std::string &path,
const std::string &body,
const std::string &content_type) {
return Patch(path, Headers(), body, content_type);
}
inline Result ClientImpl::Patch(const std::string &path,
const std::string &body,
const std::string &content_type,
@ -8702,12 +8549,6 @@ inline Result ClientImpl::Patch(const std::string &path,
return Patch(path, Headers(), body, content_type, progress);
}
inline Result ClientImpl::Patch(const std::string &path, const Headers &headers,
const std::string &body,
const std::string &content_type) {
return Patch(path, headers, body, content_type, nullptr);
}
inline Result ClientImpl::Patch(const std::string &path, const Headers &headers,
const std::string &body,
const std::string &content_type,
@ -8756,12 +8597,6 @@ inline Result ClientImpl::Delete(const std::string &path,
return Delete(path, headers, std::string(), std::string());
}
inline Result ClientImpl::Delete(const std::string &path, const char *body,
size_t content_length,
const std::string &content_type) {
return Delete(path, Headers(), body, content_length, content_type);
}
inline Result ClientImpl::Delete(const std::string &path, const char *body,
size_t content_length,
const std::string &content_type,
@ -8769,13 +8604,6 @@ inline Result ClientImpl::Delete(const std::string &path, const char *body,
return Delete(path, Headers(), body, content_length, content_type, progress);
}
inline Result ClientImpl::Delete(const std::string &path,
const Headers &headers, const char *body,
size_t content_length,
const std::string &content_type) {
return Delete(path, headers, body, content_length, content_type, nullptr);
}
inline Result ClientImpl::Delete(const std::string &path,
const Headers &headers, const char *body,
size_t content_length,
@ -8796,12 +8624,6 @@ inline Result ClientImpl::Delete(const std::string &path,
return send_(std::move(req));
}
inline Result ClientImpl::Delete(const std::string &path,
const std::string &body,
const std::string &content_type) {
return Delete(path, Headers(), body.data(), body.size(), content_type);
}
inline Result ClientImpl::Delete(const std::string &path,
const std::string &body,
const std::string &content_type,
@ -8810,13 +8632,6 @@ inline Result ClientImpl::Delete(const std::string &path,
progress);
}
inline Result ClientImpl::Delete(const std::string &path,
const Headers &headers,
const std::string &body,
const std::string &content_type) {
return Delete(path, headers, body.data(), body.size(), content_type);
}
inline Result ClientImpl::Delete(const std::string &path,
const Headers &headers,
const std::string &body,
@ -8849,8 +8664,8 @@ inline void ClientImpl::stop() {
// If there is anything ongoing right now, the ONLY thread-safe thing we can
// do is to shutdown_socket, so that threads using this socket suddenly
// discover they can't read/write any more and error out. Everything else
// (closing the socket, shutting ssl down) is unsafe because these actions are
// not thread-safe.
// (closing the socket, shutting ssl down) is unsafe because these actions
// are not thread-safe.
if (socket_requests_in_flight_ > 0) {
shutdown_socket(socket_);
@ -9475,7 +9290,8 @@ inline void SSLClient::set_ca_cert_store(X509_STORE *ca_cert_store) {
if (ca_cert_store) {
if (ctx_) {
if (SSL_CTX_get_cert_store(ctx_) != ca_cert_store) {
// Free memory allocated for old cert and use new store `ca_cert_store`
// Free memory allocated for old cert and use new store
// `ca_cert_store`
SSL_CTX_set_cert_store(ctx_, ca_cert_store);
}
} else {
@ -9499,7 +9315,6 @@ inline bool SSLClient::create_and_connect_socket(Socket &socket, Error &error) {
return is_valid() && ClientImpl::create_and_connect_socket(socket, error);
}
// Assumes that socket_mutex_ is locked and that there are no requests in flight
inline bool SSLClient::connect_with_proxy(
Socket &socket,
std::chrono::time_point<std::chrono::steady_clock> start_time,
@ -9916,10 +9731,6 @@ inline bool Client::is_valid() const {
return cli_ != nullptr && cli_->is_valid();
}
inline Result Client::Get(const std::string &path) { return cli_->Get(path); }
inline Result Client::Get(const std::string &path, const Headers &headers) {
return cli_->Get(path, headers);
}
inline Result Client::Get(const std::string &path, Progress progress) {
return cli_->Get(path, std::move(progress));
}
@ -9927,14 +9738,6 @@ inline Result Client::Get(const std::string &path, const Headers &headers,
Progress progress) {
return cli_->Get(path, headers, std::move(progress));
}
inline Result Client::Get(const std::string &path,
ContentReceiver content_receiver) {
return cli_->Get(path, std::move(content_receiver));
}
inline Result Client::Get(const std::string &path, const Headers &headers,
ContentReceiver content_receiver) {
return cli_->Get(path, headers, std::move(content_receiver));
}
inline Result Client::Get(const std::string &path,
ContentReceiver content_receiver, Progress progress) {
return cli_->Get(path, std::move(content_receiver), std::move(progress));
@ -9944,18 +9747,6 @@ inline Result Client::Get(const std::string &path, const Headers &headers,
return cli_->Get(path, headers, std::move(content_receiver),
std::move(progress));
}
inline Result Client::Get(const std::string &path,
ResponseHandler response_handler,
ContentReceiver content_receiver) {
return cli_->Get(path, std::move(response_handler),
std::move(content_receiver));
}
inline Result Client::Get(const std::string &path, const Headers &headers,
ResponseHandler response_handler,
ContentReceiver content_receiver) {
return cli_->Get(path, headers, std::move(response_handler),
std::move(content_receiver));
}
inline Result Client::Get(const std::string &path,
ResponseHandler response_handler,
ContentReceiver content_receiver, Progress progress) {
@ -9968,16 +9759,31 @@ inline Result Client::Get(const std::string &path, const Headers &headers,
return cli_->Get(path, headers, std::move(response_handler),
std::move(content_receiver), std::move(progress));
}
inline Result Client::Get(const std::string &path, const Params &params,
Progress progress) {
return cli_->Get(path, params, Headers{}, std::move(progress));
}
inline Result Client::Get(const std::string &path, const Params &params,
const Headers &headers, Progress progress) {
return cli_->Get(path, params, headers, std::move(progress));
}
inline Result Client::Get(const std::string &path, const Params &params,
ContentReceiver content_receiver, Progress progress) {
return cli_->Get(path, params, std::move(content_receiver),
std::move(progress));
}
inline Result Client::Get(const std::string &path, const Params &params,
const Headers &headers,
ContentReceiver content_receiver, Progress progress) {
return cli_->Get(path, params, headers, std::move(content_receiver),
std::move(progress));
}
inline Result Client::Get(const std::string &path, const Params &params,
ResponseHandler response_handler,
ContentReceiver content_receiver, Progress progress) {
return cli_->Get(path, params, std::move(response_handler),
std::move(content_receiver), std::move(progress));
}
inline Result Client::Get(const std::string &path, const Params &params,
const Headers &headers,
ResponseHandler response_handler,
@ -10000,30 +9806,16 @@ inline Result Client::Post(const std::string &path, const char *body,
const std::string &content_type) {
return cli_->Post(path, body, content_length, content_type);
}
inline Result Client::Post(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type) {
return cli_->Post(path, headers, body, content_length, content_type);
}
inline Result Client::Post(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type, Progress progress) {
return cli_->Post(path, headers, body, content_length, content_type,
progress);
}
inline Result Client::Post(const std::string &path, const std::string &body,
const std::string &content_type) {
return cli_->Post(path, body, content_type);
}
inline Result Client::Post(const std::string &path, const std::string &body,
const std::string &content_type, Progress progress) {
return cli_->Post(path, body, content_type, progress);
}
inline Result Client::Post(const std::string &path, const Headers &headers,
const std::string &body,
const std::string &content_type) {
return cli_->Post(path, headers, body, content_type);
}
inline Result Client::Post(const std::string &path, const Headers &headers,
const std::string &body,
const std::string &content_type, Progress progress) {
@ -10055,10 +9847,6 @@ inline Result Client::Post(const std::string &path, const Headers &headers,
inline Result Client::Post(const std::string &path, const Params &params) {
return cli_->Post(path, params);
}
inline Result Client::Post(const std::string &path, const Headers &headers,
const Params &params) {
return cli_->Post(path, headers, params);
}
inline Result Client::Post(const std::string &path, const Headers &headers,
const Params &params, Progress progress) {
return cli_->Post(path, headers, params, progress);
@ -10088,29 +9876,15 @@ inline Result Client::Put(const std::string &path, const char *body,
const std::string &content_type) {
return cli_->Put(path, body, content_length, content_type);
}
inline Result Client::Put(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type) {
return cli_->Put(path, headers, body, content_length, content_type);
}
inline Result Client::Put(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type, Progress progress) {
return cli_->Put(path, headers, body, content_length, content_type, progress);
}
inline Result Client::Put(const std::string &path, const std::string &body,
const std::string &content_type) {
return cli_->Put(path, body, content_type);
}
inline Result Client::Put(const std::string &path, const std::string &body,
const std::string &content_type, Progress progress) {
return cli_->Put(path, body, content_type, progress);
}
inline Result Client::Put(const std::string &path, const Headers &headers,
const std::string &body,
const std::string &content_type) {
return cli_->Put(path, headers, body, content_type);
}
inline Result Client::Put(const std::string &path, const Headers &headers,
const std::string &body,
const std::string &content_type, Progress progress) {
@ -10139,13 +9913,6 @@ inline Result Client::Put(const std::string &path, const Headers &headers,
const std::string &content_type) {
return cli_->Put(path, headers, std::move(content_provider), content_type);
}
inline Result Client::Put(const std::string &path, const Params &params) {
return cli_->Put(path, params);
}
inline Result Client::Put(const std::string &path, const Headers &headers,
const Params &params) {
return cli_->Put(path, headers, params);
}
inline Result Client::Put(const std::string &path, const Headers &headers,
const Params &params, Progress progress) {
return cli_->Put(path, headers, params, progress);
@ -10172,22 +9939,12 @@ Client::Put(const std::string &path, const Headers &headers,
inline Result Client::Patch(const std::string &path) {
return cli_->Patch(path);
}
inline Result Client::Patch(const std::string &path, const char *body,
size_t content_length,
const std::string &content_type) {
return cli_->Patch(path, body, content_length, content_type);
}
inline Result Client::Patch(const std::string &path, const char *body,
size_t content_length,
const std::string &content_type,
Progress progress) {
return cli_->Patch(path, body, content_length, content_type, progress);
}
inline Result Client::Patch(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type) {
return cli_->Patch(path, headers, body, content_length, content_type);
}
inline Result Client::Patch(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type,
@ -10195,20 +9952,11 @@ inline Result Client::Patch(const std::string &path, const Headers &headers,
return cli_->Patch(path, headers, body, content_length, content_type,
progress);
}
inline Result Client::Patch(const std::string &path, const std::string &body,
const std::string &content_type) {
return cli_->Patch(path, body, content_type);
}
inline Result Client::Patch(const std::string &path, const std::string &body,
const std::string &content_type,
Progress progress) {
return cli_->Patch(path, body, content_type, progress);
}
inline Result Client::Patch(const std::string &path, const Headers &headers,
const std::string &body,
const std::string &content_type) {
return cli_->Patch(path, headers, body, content_type);
}
inline Result Client::Patch(const std::string &path, const Headers &headers,
const std::string &body,
const std::string &content_type,
@ -10244,22 +9992,12 @@ inline Result Client::Delete(const std::string &path) {
inline Result Client::Delete(const std::string &path, const Headers &headers) {
return cli_->Delete(path, headers);
}
inline Result Client::Delete(const std::string &path, const char *body,
size_t content_length,
const std::string &content_type) {
return cli_->Delete(path, body, content_length, content_type);
}
inline Result Client::Delete(const std::string &path, const char *body,
size_t content_length,
const std::string &content_type,
Progress progress) {
return cli_->Delete(path, body, content_length, content_type, progress);
}
inline Result Client::Delete(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type) {
return cli_->Delete(path, headers, body, content_length, content_type);
}
inline Result Client::Delete(const std::string &path, const Headers &headers,
const char *body, size_t content_length,
const std::string &content_type,
@ -10267,20 +10005,11 @@ inline Result Client::Delete(const std::string &path, const Headers &headers,
return cli_->Delete(path, headers, body, content_length, content_type,
progress);
}
inline Result Client::Delete(const std::string &path, const std::string &body,
const std::string &content_type) {
return cli_->Delete(path, body, content_type);
}
inline Result Client::Delete(const std::string &path, const std::string &body,
const std::string &content_type,
Progress progress) {
return cli_->Delete(path, body, content_type, progress);
}
inline Result Client::Delete(const std::string &path, const Headers &headers,
const std::string &body,
const std::string &content_type) {
return cli_->Delete(path, headers, body, content_type);
}
inline Result Client::Delete(const std::string &path, const Headers &headers,
const std::string &body,
const std::string &content_type,