Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
CPPHTTPLIB_NAMESPACE::ClientImpl Class Reference
Collaboration diagram for CPPHTTPLIB_NAMESPACE::ClientImpl:

Classes

struct  Socket

Public Member Functions

 ClientImpl (const std::string &host)
 ClientImpl (const std::string &host, int port)
 ClientImpl (const std::string &host, int port, const std::string &client_cert_path, const std::string &client_key_path)
virtual bool is_valid () const
Result Get (const std::string &path, DownloadProgress progress=nullptr)
Result Get (const std::string &path, ContentReceiver content_receiver, DownloadProgress progress=nullptr)
Result Get (const std::string &path, ResponseHandler response_handler, ContentReceiver content_receiver, DownloadProgress progress=nullptr)
Result Get (const std::string &path, const Headers &headers, DownloadProgress progress=nullptr)
Result Get (const std::string &path, const Headers &headers, ContentReceiver content_receiver, DownloadProgress progress=nullptr)
Result Get (const std::string &path, const Headers &headers, ResponseHandler response_handler, ContentReceiver content_receiver, DownloadProgress progress=nullptr)
Result Get (const std::string &path, const Params &params, const Headers &headers, DownloadProgress progress=nullptr)
Result Get (const std::string &path, const Params &params, const Headers &headers, ContentReceiver content_receiver, DownloadProgress progress=nullptr)
Result Get (const std::string &path, const Params &params, const Headers &headers, ResponseHandler response_handler, ContentReceiver content_receiver, DownloadProgress progress=nullptr)
Result Head (const std::string &path)
Result Head (const std::string &path, const Headers &headers)
Result Post (const std::string &path)
Result Post (const std::string &path, const char *body, size_t content_length, const std::string &content_type, UploadProgress progress=nullptr)
Result Post (const std::string &path, const std::string &body, const std::string &content_type, UploadProgress progress=nullptr)
Result Post (const std::string &path, size_t content_length, ContentProvider content_provider, const std::string &content_type, UploadProgress progress=nullptr)
Result Post (const std::string &path, ContentProviderWithoutLength content_provider, const std::string &content_type, UploadProgress progress=nullptr)
Result Post (const std::string &path, const Params &params)
Result Post (const std::string &path, const UploadFormDataItems &items, UploadProgress progress=nullptr)
Result Post (const std::string &path, const Headers &headers)
Result Post (const std::string &path, const Headers &headers, const char *body, size_t content_length, const std::string &content_type, UploadProgress progress=nullptr)
Result Post (const std::string &path, const Headers &headers, const std::string &body, const std::string &content_type, UploadProgress progress=nullptr)
Result Post (const std::string &path, const Headers &headers, size_t content_length, ContentProvider content_provider, const std::string &content_type, UploadProgress progress=nullptr)
Result Post (const std::string &path, const Headers &headers, ContentProviderWithoutLength content_provider, const std::string &content_type, UploadProgress progress=nullptr)
Result Post (const std::string &path, const Headers &headers, const Params &params)
Result Post (const std::string &path, const Headers &headers, const UploadFormDataItems &items, UploadProgress progress=nullptr)
Result Post (const std::string &path, const Headers &headers, const UploadFormDataItems &items, const std::string &boundary, UploadProgress progress=nullptr)
Result Post (const std::string &path, const Headers &headers, const UploadFormDataItems &items, const FormDataProviderItems &provider_items, UploadProgress progress=nullptr)
Result Post (const std::string &path, const Headers &headers, const std::string &body, const std::string &content_type, ContentReceiver content_receiver, DownloadProgress progress=nullptr)
Result Put (const std::string &path)
Result Put (const std::string &path, const char *body, size_t content_length, const std::string &content_type, UploadProgress progress=nullptr)
Result Put (const std::string &path, const std::string &body, const std::string &content_type, UploadProgress progress=nullptr)
Result Put (const std::string &path, size_t content_length, ContentProvider content_provider, const std::string &content_type, UploadProgress progress=nullptr)
Result Put (const std::string &path, ContentProviderWithoutLength content_provider, const std::string &content_type, UploadProgress progress=nullptr)
Result Put (const std::string &path, const Params &params)
Result Put (const std::string &path, const UploadFormDataItems &items, UploadProgress progress=nullptr)
Result Put (const std::string &path, const Headers &headers)
Result Put (const std::string &path, const Headers &headers, const char *body, size_t content_length, const std::string &content_type, UploadProgress progress=nullptr)
Result Put (const std::string &path, const Headers &headers, const std::string &body, const std::string &content_type, UploadProgress progress=nullptr)
Result Put (const std::string &path, const Headers &headers, size_t content_length, ContentProvider content_provider, const std::string &content_type, UploadProgress progress=nullptr)
Result Put (const std::string &path, const Headers &headers, ContentProviderWithoutLength content_provider, const std::string &content_type, UploadProgress progress=nullptr)
Result Put (const std::string &path, const Headers &headers, const Params &params)
Result Put (const std::string &path, const Headers &headers, const UploadFormDataItems &items, UploadProgress progress=nullptr)
Result Put (const std::string &path, const Headers &headers, const UploadFormDataItems &items, const std::string &boundary, UploadProgress progress=nullptr)
Result Put (const std::string &path, const Headers &headers, const UploadFormDataItems &items, const FormDataProviderItems &provider_items, UploadProgress progress=nullptr)
Result Put (const std::string &path, const Headers &headers, const std::string &body, const std::string &content_type, ContentReceiver content_receiver, DownloadProgress progress=nullptr)
Result Patch (const std::string &path)
Result Patch (const std::string &path, const char *body, size_t content_length, const std::string &content_type, UploadProgress progress=nullptr)
Result Patch (const std::string &path, const std::string &body, const std::string &content_type, UploadProgress progress=nullptr)
Result Patch (const std::string &path, size_t content_length, ContentProvider content_provider, const std::string &content_type, UploadProgress progress=nullptr)
Result Patch (const std::string &path, ContentProviderWithoutLength content_provider, const std::string &content_type, UploadProgress progress=nullptr)
Result Patch (const std::string &path, const Params &params)
Result Patch (const std::string &path, const UploadFormDataItems &items, UploadProgress progress=nullptr)
Result Patch (const std::string &path, const Headers &headers, UploadProgress progress=nullptr)
Result Patch (const std::string &path, const Headers &headers, const char *body, size_t content_length, const std::string &content_type, UploadProgress progress=nullptr)
Result Patch (const std::string &path, const Headers &headers, const std::string &body, const std::string &content_type, UploadProgress progress=nullptr)
Result Patch (const std::string &path, const Headers &headers, size_t content_length, ContentProvider content_provider, const std::string &content_type, UploadProgress progress=nullptr)
Result Patch (const std::string &path, const Headers &headers, ContentProviderWithoutLength content_provider, const std::string &content_type, UploadProgress progress=nullptr)
Result Patch (const std::string &path, const Headers &headers, const Params &params)
Result Patch (const std::string &path, const Headers &headers, const UploadFormDataItems &items, UploadProgress progress=nullptr)
Result Patch (const std::string &path, const Headers &headers, const UploadFormDataItems &items, const std::string &boundary, UploadProgress progress=nullptr)
Result Patch (const std::string &path, const Headers &headers, const UploadFormDataItems &items, const FormDataProviderItems &provider_items, UploadProgress progress=nullptr)
Result Patch (const std::string &path, const Headers &headers, const std::string &body, const std::string &content_type, ContentReceiver content_receiver, DownloadProgress progress=nullptr)
Result Delete (const std::string &path, DownloadProgress progress=nullptr)
Result Delete (const std::string &path, const char *body, size_t content_length, const std::string &content_type, DownloadProgress progress=nullptr)
Result Delete (const std::string &path, const std::string &body, const std::string &content_type, DownloadProgress progress=nullptr)
Result Delete (const std::string &path, const Params &params, DownloadProgress progress=nullptr)
Result Delete (const std::string &path, const Headers &headers, DownloadProgress progress=nullptr)
Result Delete (const std::string &path, const Headers &headers, const char *body, size_t content_length, const std::string &content_type, DownloadProgress progress=nullptr)
Result Delete (const std::string &path, const Headers &headers, const std::string &body, const std::string &content_type, DownloadProgress progress=nullptr)
Result Delete (const std::string &path, const Headers &headers, const Params &params, DownloadProgress progress=nullptr)
Result Options (const std::string &path)
Result Options (const std::string &path, const Headers &headers)
bool send (Request &req, Response &res, Error &error)
Result send (const Request &req)
void stop ()
std::string host () const
int port () const
size_t is_socket_open () const
socket_t socket () const
void set_hostname_addr_map (std::map< std::string, std::string > addr_map)
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_ipv6_v6only (bool on)
void set_socket_options (SocketOptions socket_options)
void set_connection_timeout (time_t sec, time_t usec=0)
template<class Rep, class Period>
void set_connection_timeout (const std::chrono::duration< Rep, Period > &duration)
void set_read_timeout (time_t sec, time_t usec=0)
template<class Rep, class Period>
void set_read_timeout (const std::chrono::duration< Rep, Period > &duration)
void set_write_timeout (time_t sec, time_t usec=0)
template<class Rep, class Period>
void set_write_timeout (const std::chrono::duration< Rep, Period > &duration)
void set_max_timeout (time_t msec)
template<class Rep, class Period>
void set_max_timeout (const std::chrono::duration< Rep, Period > &duration)
void set_basic_auth (const std::string &username, const std::string &password)
void set_bearer_token_auth (const std::string &token)
void set_keep_alive (bool on)
void set_follow_location (bool on)
void set_path_encode (bool on)
void set_compress (bool on)
void set_decompress (bool on)
void set_interface (const std::string &intf)
void set_proxy (const std::string &host, int port)
void set_proxy_basic_auth (const std::string &username, const std::string &password)
void set_proxy_bearer_token_auth (const std::string &token)
void set_logger (Logger logger)
void set_error_logger (ErrorLogger error_logger)

Protected Member Functions

virtual bool create_and_connect_socket (Socket &socket, Error &error)
virtual void shutdown_ssl (Socket &socket, bool shutdown_gracefully)
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) const
void copy_settings (const ClientImpl &rhs)
void output_log (const Request &req, const Response &res) const
void output_error_log (const Error &err, const Request *req) const

Protected Attributes

const std::string host_
const int port_
const std::string host_and_port_
Socket socket_
std::mutex socket_mutex_
std::recursive_mutex request_mutex_
size_t socket_requests_in_flight_ = 0
std::thread::id socket_requests_are_from_thread_ = std::thread::id()
bool socket_should_be_closed_when_request_is_done_ = false
std::map< std::string, std::string > addr_map_
Headers default_headers_
std::function< ssize_t(Stream &, Headers &)> header_writer_
std::string client_cert_path_
std::string client_key_path_
time_t connection_timeout_sec_ = CPPHTTPLIB_CONNECTION_TIMEOUT_SECOND
time_t connection_timeout_usec_ = CPPHTTPLIB_CONNECTION_TIMEOUT_USECOND
time_t read_timeout_sec_ = CPPHTTPLIB_CLIENT_READ_TIMEOUT_SECOND
time_t read_timeout_usec_ = CPPHTTPLIB_CLIENT_READ_TIMEOUT_USECOND
time_t write_timeout_sec_ = CPPHTTPLIB_CLIENT_WRITE_TIMEOUT_SECOND
time_t write_timeout_usec_ = CPPHTTPLIB_CLIENT_WRITE_TIMEOUT_USECOND
time_t max_timeout_msec_ = CPPHTTPLIB_CLIENT_MAX_TIMEOUT_MSECOND
std::string basic_auth_username_
std::string basic_auth_password_
std::string bearer_token_auth_token_
bool keep_alive_ = false
bool follow_location_ = false
bool path_encode_ = true
int address_family_ = AF_UNSPEC
bool tcp_nodelay_ = CPPHTTPLIB_TCP_NODELAY
bool ipv6_v6only_ = CPPHTTPLIB_IPV6_V6ONLY
SocketOptions socket_options_ = nullptr
bool compress_ = false
bool decompress_ = true
std::string interface_
std::string proxy_host_
int proxy_port_ = -1
std::string proxy_basic_auth_username_
std::string proxy_basic_auth_password_
std::string proxy_bearer_token_auth_token_
std::mutex logger_mutex_
Logger logger_
ErrorLogger error_logger_

Private Member Functions

bool send_ (Request &req, Response &res, Error &error)
Result send_ (Request &&req)
socket_t create_client_socket (Error &error) const
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)
bool create_redirect_client (const std::string &scheme, const std::string &host, int port, Request &req, Response &res, const std::string &path, const std::string &location, Error &error)
template<typename ClientType>
void setup_redirect_client (ClientType &client)
bool handle_request (Stream &strm, Request &req, Response &res, bool close_connection, Error &error)
duckdb::unique_ptr< Response > send_with_content_provider (Request &req, const char *body, size_t content_length, ContentProvider content_provider, ContentProviderWithoutLength content_provider_without_length, const std::string &content_type, Error &error)
Result send_with_content_provider (const std::string &method, const std::string &path, const Headers &headers, const char *body, size_t content_length, ContentProvider content_provider, ContentProviderWithoutLength content_provider_without_length, const std::string &content_type, UploadProgress progress)
ContentProviderWithoutLength get_multipart_content_provider (const std::string &boundary, const UploadFormDataItems &items, const FormDataProviderItems &provider_items) const
virtual bool process_socket (const Socket &socket, std::chrono::time_point< std::chrono::steady_clock > start_time, std::function< bool(Stream &strm)> callback)
virtual bool is_ssl () const

Constructor & Destructor Documentation

◆ ClientImpl() [1/3]

CPPHTTPLIB_NAMESPACE::ClientImpl::ClientImpl ( const std::string & host)
inlineexplicit
290151 : ClientImpl(host, 80, std::string(), std::string()) {}

◆ ClientImpl() [2/3]

CPPHTTPLIB_NAMESPACE::ClientImpl::ClientImpl ( const std::string & host,
int port )
inlineexplicit
290154 : ClientImpl(host, port, std::string(), std::string()) {}

◆ ClientImpl() [3/3]

CPPHTTPLIB_NAMESPACE::ClientImpl::ClientImpl ( const std::string & host,
int port,
const std::string & client_cert_path,
const std::string & client_key_path )
inlineexplicit
290159 : host_(detail::escape_abstract_namespace_unix_domain(host)), port_(port),
290160 host_and_port_(detail::make_host_and_port_string(host_, port, is_ssl())),
290161 client_cert_path_(client_cert_path), client_key_path_(client_key_path) {}

◆ ~ClientImpl()

CPPHTTPLIB_NAMESPACE::ClientImpl::~ClientImpl ( )
inlinevirtual
290163 {
290164 // Wait until all the requests in flight are handled.
290165 size_t retry_count = 10;
290166 while (retry_count-- > 0) {
290167 {
290168 std::lock_guard<std::mutex> guard(socket_mutex_);
290169 if (socket_requests_in_flight_ == 0) { break; }
290170 }
290171 std::this_thread::sleep_for(std::chrono::milliseconds{1});
290172 }
290173
290174 std::lock_guard<std::mutex> guard(socket_mutex_);
290175 shutdown_socket(socket_);
290176 close_socket(socket_);
290177}

Member Function Documentation

◆ is_valid()

bool CPPHTTPLIB_NAMESPACE::ClientImpl::is_valid ( ) const
inlinevirtual
290179{ return true; }

◆ Get() [1/9]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Get ( const std::string & path,
DownloadProgress progress = nullptr )
inline
291218 {
291219 return Get(path, Headers(), std::move(progress));
291220}

◆ Get() [2/9]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Get ( const std::string & path,
ContentReceiver content_receiver,
DownloadProgress progress = nullptr )
inline
291247 {
291248 return Get(path, Headers(), nullptr, std::move(content_receiver),
291249 std::move(progress));
291250}

◆ Get() [3/9]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Get ( const std::string & path,
ResponseHandler response_handler,
ContentReceiver content_receiver,
DownloadProgress progress = nullptr )
inline
291262 {
291263 return Get(path, Headers(), std::move(response_handler),
291264 std::move(content_receiver), std::move(progress));
291265}

◆ Get() [4/9]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Get ( const std::string & path,
const Headers & headers,
DownloadProgress progress = nullptr )
inline
291232 {
291233 Request req;
291234 req.method = "GET";
291235 req.path = path;
291236 req.headers = headers;
291237 req.download_progress = std::move(progress);
291238 if (max_timeout_msec_ > 0) {
291239 req.start_time_ = std::chrono::steady_clock::now();
291240 }
291241
291242 return send_(std::move(req));
291243}

◆ Get() [5/9]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Get ( const std::string & path,
const Headers & headers,
ContentReceiver content_receiver,
DownloadProgress progress = nullptr )
inline
291254 {
291255 return Get(path, headers, nullptr, std::move(content_receiver),
291256 std::move(progress));
291257}

◆ Get() [6/9]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Get ( const std::string & path,
const Headers & headers,
ResponseHandler response_handler,
ContentReceiver content_receiver,
DownloadProgress progress = nullptr )
inline
291270 {
291271 Request req;
291272 req.method = "GET";
291273 req.path = path;
291274 req.headers = headers;
291275 req.response_handler = std::move(response_handler);
291276 req.content_receiver =
291277 [content_receiver](const char *data, size_t data_length,
291278 size_t /*offset*/, size_t /*total_length*/) {
291279 return content_receiver(data, data_length);
291280 };
291281 req.download_progress = std::move(progress);
291282 if (max_timeout_msec_ > 0) {
291283 req.start_time_ = std::chrono::steady_clock::now();
291284 }
291285
291286 return send_(std::move(req));
291287}

◆ Get() [7/9]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Get ( const std::string & path,
const Params & params,
const Headers & headers,
DownloadProgress progress = nullptr )
inline
291224 {
291225 if (params.empty()) { return Get(path, headers); }
291226
291227 std::string path_with_query = append_query_params(path, params);
291228 return Get(path_with_query, headers, std::move(progress));
291229}
PyParams params(const std::string &tag, const std::string &model, const std::string &weights, const std::string &device)

◆ Get() [8/9]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Get ( const std::string & path,
const Params & params,
const Headers & headers,
ContentReceiver content_receiver,
DownloadProgress progress = nullptr )
inline
291292 {
291293 return Get(path, params, headers, nullptr, std::move(content_receiver),
291294 std::move(progress));
291295}

◆ Get() [9/9]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Get ( const std::string & path,
const Params & params,
const Headers & headers,
ResponseHandler response_handler,
ContentReceiver content_receiver,
DownloadProgress progress = nullptr )
inline
291301 {
291302 if (params.empty()) {
291303 return Get(path, headers, std::move(response_handler),
291304 std::move(content_receiver), std::move(progress));
291305 }
291306
291307 std::string path_with_query = append_query_params(path, params);
291308 return Get(path_with_query, headers, std::move(response_handler),
291309 std::move(content_receiver), std::move(progress));
291310}

◆ Head() [1/2]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Head ( const std::string & path)
inline
291312 {
291313 return Head(path, Headers());
291314}

◆ Head() [2/2]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Head ( const std::string & path,
const Headers & headers )
inline
291317 {
291318 Request req;
291319 req.method = "HEAD";
291320 req.headers = headers;
291321 req.path = path;
291322 if (max_timeout_msec_ > 0) {
291323 req.start_time_ = std::chrono::steady_clock::now();
291324 }
291325
291326 return send_(std::move(req));
291327}

◆ Post() [1/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Post ( const std::string & path)
inline
291329 {
291330 return Post(path, std::string(), std::string());
291331}

◆ Post() [2/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Post ( const std::string & path,
const char * body,
size_t content_length,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291341 {
291342 return Post(path, Headers(), body, content_length, content_type, progress);
291343}

◆ Post() [3/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Post ( const std::string & path,
const std::string & body,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291347 {
291348 return Post(path, Headers(), body, content_type, progress);
291349}

◆ Post() [4/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Post ( const std::string & path,
size_t content_length,
ContentProvider content_provider,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291358 {
291359 return Post(path, Headers(), content_length, std::move(content_provider),
291360 content_type, progress);
291361}

◆ Post() [5/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Post ( const std::string & path,
ContentProviderWithoutLength content_provider,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291366 {
291367 return Post(path, Headers(), std::move(content_provider), content_type,
291368 progress);
291369}

◆ Post() [6/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Post ( const std::string & path,
const Params & params )
inline
291351 {
291352 return Post(path, Headers(), params);
291353}

◆ Post() [7/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Post ( const std::string & path,
const UploadFormDataItems & items,
UploadProgress progress = nullptr )
inline
291379 {
291380 return Post(path, Headers(), items, progress);
291381}

◆ Post() [8/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Post ( const std::string & path,
const Headers & headers )
inline
291334 {
291335 return Post(path, headers, nullptr, 0, std::string());
291336}

◆ Post() [9/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Post ( const std::string & path,
const Headers & headers,
const char * body,
size_t content_length,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291410 {
291411 return send_with_content_provider("POST", path, headers, body, content_length,
291412 nullptr, nullptr, content_type, progress);
291413}

◆ Post() [10/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Post ( const std::string & path,
const Headers & headers,
const std::string & body,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291418 {
291419 return send_with_content_provider("POST", path, headers, body.data(),
291420 body.size(), nullptr, nullptr, content_type,
291421 progress);
291422}

◆ Post() [11/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Post ( const std::string & path,
const Headers & headers,
size_t content_length,
ContentProvider content_provider,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291428 {
291429 return send_with_content_provider("POST", path, headers, nullptr,
291430 content_length, std::move(content_provider),
291431 nullptr, content_type, progress);
291432}

◆ Post() [12/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Post ( const std::string & path,
const Headers & headers,
ContentProviderWithoutLength content_provider,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291437 {
291438 return send_with_content_provider("POST", path, headers, nullptr, 0, nullptr,
291439 std::move(content_provider), content_type,
291440 progress);
291441}

◆ Post() [13/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Post ( const std::string & path,
const Headers & headers,
const Params & params )
inline
291372 {
291373 auto query = detail::params_to_query_str(params);
291374 return Post(path, headers, query, "application/x-www-form-urlencoded");
291375}

◆ Post() [14/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Post ( const std::string & path,
const Headers & headers,
const UploadFormDataItems & items,
UploadProgress progress = nullptr )
inline
291385 {
291386 const auto &boundary = detail::make_multipart_data_boundary();
291387 const auto &content_type =
291388 detail::serialize_multipart_formdata_get_content_type(boundary);
291389 const auto &body = detail::serialize_multipart_formdata(items, boundary);
291390 return Post(path, headers, body, content_type, progress);
291391}

◆ Post() [15/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Post ( const std::string & path,
const Headers & headers,
const UploadFormDataItems & items,
const std::string & boundary,
UploadProgress progress = nullptr )
inline
291396 {
291397 if (!detail::is_multipart_boundary_chars_valid(boundary)) {
291398 return Result{nullptr, Error::UnsupportedMultipartBoundaryChars};
291399 }
291400
291401 const auto &content_type =
291402 detail::serialize_multipart_formdata_get_content_type(boundary);
291403 const auto &body = detail::serialize_multipart_formdata(items, boundary);
291404 return Post(path, headers, body, content_type, progress);
291405}

◆ Post() [16/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Post ( const std::string & path,
const Headers & headers,
const UploadFormDataItems & items,
const FormDataProviderItems & provider_items,
UploadProgress progress = nullptr )
inline
291446 {
291447 const auto &boundary = detail::make_multipart_data_boundary();
291448 const auto &content_type =
291449 detail::serialize_multipart_formdata_get_content_type(boundary);
291450 return send_with_content_provider(
291451 "POST", path, headers, nullptr, 0, nullptr,
291452 get_multipart_content_provider(boundary, items, provider_items),
291453 content_type, progress);
291454}

◆ Post() [17/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Post ( const std::string & path,
const Headers & headers,
const std::string & body,
const std::string & content_type,
ContentReceiver content_receiver,
DownloadProgress progress = nullptr )
inline
291460 {
291461 Request req;
291462 req.method = "POST";
291463 req.path = path;
291464 req.headers = headers;
291465 req.body = body;
291466 req.content_receiver =
291467 [content_receiver](const char *data, size_t data_length,
291468 size_t /*offset*/, size_t /*total_length*/) {
291469 return content_receiver(data, data_length);
291470 };
291471 req.download_progress = std::move(progress);
291472
291473 if (max_timeout_msec_ > 0) {
291474 req.start_time_ = std::chrono::steady_clock::now();
291475 }
291476
291477 if (!content_type.empty()) { req.set_header("Content-Type", content_type); }
291478
291479 return send_(std::move(req));
291480}

◆ Put() [1/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Put ( const std::string & path)
inline
291482 {
291483 return Put(path, std::string(), std::string());
291484}

◆ Put() [2/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Put ( const std::string & path,
const char * body,
size_t content_length,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291493 {
291494 return Put(path, Headers(), body, content_length, content_type, progress);
291495}

◆ Put() [3/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Put ( const std::string & path,
const std::string & body,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291499 {
291500 return Put(path, Headers(), body, content_type, progress);
291501}

◆ Put() [4/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Put ( const std::string & path,
size_t content_length,
ContentProvider content_provider,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291510 {
291511 return Put(path, Headers(), content_length, std::move(content_provider),
291512 content_type, progress);
291513}

◆ Put() [5/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Put ( const std::string & path,
ContentProviderWithoutLength content_provider,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291518 {
291519 return Put(path, Headers(), std::move(content_provider), content_type,
291520 progress);
291521}

◆ Put() [6/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Put ( const std::string & path,
const Params & params )
inline
291503 {
291504 return Put(path, Headers(), params);
291505}

◆ Put() [7/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Put ( const std::string & path,
const UploadFormDataItems & items,
UploadProgress progress = nullptr )
inline
291531 {
291532 return Put(path, Headers(), items, progress);
291533}

◆ Put() [8/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Put ( const std::string & path,
const Headers & headers )
inline
291486 {
291487 return Put(path, headers, nullptr, 0, std::string());
291488}

◆ Put() [9/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Put ( const std::string & path,
const Headers & headers,
const char * body,
size_t content_length,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291562 {
291563 return send_with_content_provider("PUT", path, headers, body, content_length,
291564 nullptr, nullptr, content_type, progress);
291565}

◆ Put() [10/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Put ( const std::string & path,
const Headers & headers,
const std::string & body,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291570 {
291571 return send_with_content_provider("PUT", path, headers, body.data(),
291572 body.size(), nullptr, nullptr, content_type,
291573 progress);
291574}

◆ Put() [11/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Put ( const std::string & path,
const Headers & headers,
size_t content_length,
ContentProvider content_provider,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291580 {
291581 return send_with_content_provider("PUT", path, headers, nullptr,
291582 content_length, std::move(content_provider),
291583 nullptr, content_type, progress);
291584}

◆ Put() [12/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Put ( const std::string & path,
const Headers & headers,
ContentProviderWithoutLength content_provider,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291589 {
291590 return send_with_content_provider("PUT", path, headers, nullptr, 0, nullptr,
291591 std::move(content_provider), content_type,
291592 progress);
291593}

◆ Put() [13/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Put ( const std::string & path,
const Headers & headers,
const Params & params )
inline
291524 {
291525 auto query = detail::params_to_query_str(params);
291526 return Put(path, headers, query, "application/x-www-form-urlencoded");
291527}

◆ Put() [14/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Put ( const std::string & path,
const Headers & headers,
const UploadFormDataItems & items,
UploadProgress progress = nullptr )
inline
291537 {
291538 const auto &boundary = detail::make_multipart_data_boundary();
291539 const auto &content_type =
291540 detail::serialize_multipart_formdata_get_content_type(boundary);
291541 const auto &body = detail::serialize_multipart_formdata(items, boundary);
291542 return Put(path, headers, body, content_type, progress);
291543}

◆ Put() [15/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Put ( const std::string & path,
const Headers & headers,
const UploadFormDataItems & items,
const std::string & boundary,
UploadProgress progress = nullptr )
inline
291548 {
291549 if (!detail::is_multipart_boundary_chars_valid(boundary)) {
291550 return Result{nullptr, Error::UnsupportedMultipartBoundaryChars};
291551 }
291552
291553 const auto &content_type =
291554 detail::serialize_multipart_formdata_get_content_type(boundary);
291555 const auto &body = detail::serialize_multipart_formdata(items, boundary);
291556 return Put(path, headers, body, content_type, progress);
291557}

◆ Put() [16/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Put ( const std::string & path,
const Headers & headers,
const UploadFormDataItems & items,
const FormDataProviderItems & provider_items,
UploadProgress progress = nullptr )
inline
291598 {
291599 const auto &boundary = detail::make_multipart_data_boundary();
291600 const auto &content_type =
291601 detail::serialize_multipart_formdata_get_content_type(boundary);
291602 return send_with_content_provider(
291603 "PUT", path, headers, nullptr, 0, nullptr,
291604 get_multipart_content_provider(boundary, items, provider_items),
291605 content_type, progress);
291606}

◆ Put() [17/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Put ( const std::string & path,
const Headers & headers,
const std::string & body,
const std::string & content_type,
ContentReceiver content_receiver,
DownloadProgress progress = nullptr )
inline
291612 {
291613 Request req;
291614 req.method = "PUT";
291615 req.path = path;
291616 req.headers = headers;
291617 req.body = body;
291618 req.content_receiver =
291619 [content_receiver](const char *data, size_t data_length,
291620 size_t /*offset*/, size_t /*total_length*/) {
291621 return content_receiver(data, data_length);
291622 };
291623 req.download_progress = std::move(progress);
291624
291625 if (max_timeout_msec_ > 0) {
291626 req.start_time_ = std::chrono::steady_clock::now();
291627 }
291628
291629 if (!content_type.empty()) { req.set_header("Content-Type", content_type); }
291630
291631 return send_(std::move(req));
291632}

◆ Patch() [1/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Patch ( const std::string & path)
inline
291634 {
291635 return Patch(path, std::string(), std::string());
291636}

◆ Patch() [2/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Patch ( const std::string & path,
const char * body,
size_t content_length,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291646 {
291647 return Patch(path, Headers(), body, content_length, content_type, progress);
291648}

◆ Patch() [3/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Patch ( const std::string & path,
const std::string & body,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291653 {
291654 return Patch(path, Headers(), body, content_type, progress);
291655}

◆ Patch() [4/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Patch ( const std::string & path,
size_t content_length,
ContentProvider content_provider,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291664 {
291665 return Patch(path, Headers(), content_length, std::move(content_provider),
291666 content_type, progress);
291667}

◆ Patch() [5/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Patch ( const std::string & path,
ContentProviderWithoutLength content_provider,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291672 {
291673 return Patch(path, Headers(), std::move(content_provider), content_type,
291674 progress);
291675}

◆ Patch() [6/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Patch ( const std::string & path,
const Params & params )
inline
291657 {
291658 return Patch(path, Headers(), params);
291659}

◆ Patch() [7/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Patch ( const std::string & path,
const UploadFormDataItems & items,
UploadProgress progress = nullptr )
inline
291685 {
291686 return Patch(path, Headers(), items, progress);
291687}

◆ Patch() [8/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Patch ( const std::string & path,
const Headers & headers,
UploadProgress progress = nullptr )
inline
291639 {
291640 return Patch(path, headers, nullptr, 0, std::string(), progress);
291641}

◆ Patch() [9/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Patch ( const std::string & path,
const Headers & headers,
const char * body,
size_t content_length,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291716 {
291717 return send_with_content_provider("PATCH", path, headers, body,
291718 content_length, nullptr, nullptr,
291719 content_type, progress);
291720}

◆ Patch() [10/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Patch ( const std::string & path,
const Headers & headers,
const std::string & body,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291725 {
291726 return send_with_content_provider("PATCH", path, headers, body.data(),
291727 body.size(), nullptr, nullptr, content_type,
291728 progress);
291729}

◆ Patch() [11/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Patch ( const std::string & path,
const Headers & headers,
size_t content_length,
ContentProvider content_provider,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291735 {
291736 return send_with_content_provider("PATCH", path, headers, nullptr,
291737 content_length, std::move(content_provider),
291738 nullptr, content_type, progress);
291739}

◆ Patch() [12/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Patch ( const std::string & path,
const Headers & headers,
ContentProviderWithoutLength content_provider,
const std::string & content_type,
UploadProgress progress = nullptr )
inline
291744 {
291745 return send_with_content_provider("PATCH", path, headers, nullptr, 0, nullptr,
291746 std::move(content_provider), content_type,
291747 progress);
291748}

◆ Patch() [13/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Patch ( const std::string & path,
const Headers & headers,
const Params & params )
inline
291678 {
291679 auto query = detail::params_to_query_str(params);
291680 return Patch(path, headers, query, "application/x-www-form-urlencoded");
291681}

◆ Patch() [14/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Patch ( const std::string & path,
const Headers & headers,
const UploadFormDataItems & items,
UploadProgress progress = nullptr )
inline
291691 {
291692 const auto &boundary = detail::make_multipart_data_boundary();
291693 const auto &content_type =
291694 detail::serialize_multipart_formdata_get_content_type(boundary);
291695 const auto &body = detail::serialize_multipart_formdata(items, boundary);
291696 return Patch(path, headers, body, content_type, progress);
291697}

◆ Patch() [15/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Patch ( const std::string & path,
const Headers & headers,
const UploadFormDataItems & items,
const std::string & boundary,
UploadProgress progress = nullptr )
inline
291702 {
291703 if (!detail::is_multipart_boundary_chars_valid(boundary)) {
291704 return Result{nullptr, Error::UnsupportedMultipartBoundaryChars};
291705 }
291706
291707 const auto &content_type =
291708 detail::serialize_multipart_formdata_get_content_type(boundary);
291709 const auto &body = detail::serialize_multipart_formdata(items, boundary);
291710 return Patch(path, headers, body, content_type, progress);
291711}

◆ Patch() [16/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Patch ( const std::string & path,
const Headers & headers,
const UploadFormDataItems & items,
const FormDataProviderItems & provider_items,
UploadProgress progress = nullptr )
inline
291753 {
291754 const auto &boundary = detail::make_multipart_data_boundary();
291755 const auto &content_type =
291756 detail::serialize_multipart_formdata_get_content_type(boundary);
291757 return send_with_content_provider(
291758 "PATCH", path, headers, nullptr, 0, nullptr,
291759 get_multipart_content_provider(boundary, items, provider_items),
291760 content_type, progress);
291761}

◆ Patch() [17/17]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Patch ( const std::string & path,
const Headers & headers,
const std::string & body,
const std::string & content_type,
ContentReceiver content_receiver,
DownloadProgress progress = nullptr )
inline
291767 {
291768 Request req;
291769 req.method = "PATCH";
291770 req.path = path;
291771 req.headers = headers;
291772 req.body = body;
291773 req.content_receiver =
291774 [content_receiver](const char *data, size_t data_length,
291775 size_t /*offset*/, size_t /*total_length*/) {
291776 return content_receiver(data, data_length);
291777 };
291778 req.download_progress = std::move(progress);
291779
291780 if (max_timeout_msec_ > 0) {
291781 req.start_time_ = std::chrono::steady_clock::now();
291782 }
291783
291784 if (!content_type.empty()) { req.set_header("Content-Type", content_type); }
291785
291786 return send_(std::move(req));
291787}

◆ Delete() [1/8]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Delete ( const std::string & path,
DownloadProgress progress = nullptr )
inline
291790 {
291791 return Delete(path, Headers(), std::string(), std::string(), progress);
291792}

◆ Delete() [2/8]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Delete ( const std::string & path,
const char * body,
size_t content_length,
const std::string & content_type,
DownloadProgress progress = nullptr )
inline
291803 {
291804 return Delete(path, Headers(), body, content_length, content_type, progress);
291805}

◆ Delete() [3/8]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Delete ( const std::string & path,
const std::string & body,
const std::string & content_type,
DownloadProgress progress = nullptr )
inline
291810 {
291811 return Delete(path, Headers(), body.data(), body.size(), content_type,
291812 progress);
291813}

◆ Delete() [4/8]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Delete ( const std::string & path,
const Params & params,
DownloadProgress progress = nullptr )
inline
291825 {
291826 return Delete(path, Headers(), params, progress);
291827}

◆ Delete() [5/8]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Delete ( const std::string & path,
const Headers & headers,
DownloadProgress progress = nullptr )
inline
291796 {
291797 return Delete(path, headers, std::string(), std::string(), progress);
291798}

◆ Delete() [6/8]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Delete ( const std::string & path,
const Headers & headers,
const char * body,
size_t content_length,
const std::string & content_type,
DownloadProgress progress = nullptr )
inline
291841 {
291842 Request req;
291843 req.method = "DELETE";
291844 req.headers = headers;
291845 req.path = path;
291846 req.download_progress = std::move(progress);
291847 if (max_timeout_msec_ > 0) {
291848 req.start_time_ = std::chrono::steady_clock::now();
291849 }
291850
291851 if (!content_type.empty()) { req.set_header("Content-Type", content_type); }
291852 req.body.assign(body, content_length);
291853
291854 return send_(std::move(req));
291855}

◆ Delete() [7/8]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Delete ( const std::string & path,
const Headers & headers,
const std::string & body,
const std::string & content_type,
DownloadProgress progress = nullptr )
inline
291819 {
291820 return Delete(path, headers, body.data(), body.size(), content_type,
291821 progress);
291822}

◆ Delete() [8/8]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Delete ( const std::string & path,
const Headers & headers,
const Params & params,
DownloadProgress progress = nullptr )
inline
291831 {
291832 auto query = detail::params_to_query_str(params);
291833 return Delete(path, headers, query, "application/x-www-form-urlencoded",
291834 progress);
291835}

◆ Options() [1/2]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Options ( const std::string & path)
inline
291857 {
291858 return Options(path, Headers());
291859}

◆ Options() [2/2]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::Options ( const std::string & path,
const Headers & headers )
inline
291862 {
291863 Request req;
291864 req.method = "OPTIONS";
291865 req.headers = headers;
291866 req.path = path;
291867 if (max_timeout_msec_ > 0) {
291868 req.start_time_ = std::chrono::steady_clock::now();
291869 }
291870
291871 return send_(std::move(req));
291872}

◆ send() [1/2]

bool CPPHTTPLIB_NAMESPACE::ClientImpl::send ( Request & req,
Response & res,
Error & error )
inline
290327 {
290328 std::lock_guard<std::recursive_mutex> request_mutex_guard(request_mutex_);
290329 auto ret = send_(req, res, error);
290330 if (error == Error::SSLPeerCouldBeClosed_) {
290331 assert(!ret);
290332 ret = send_(req, res, error);
290333 }
290334 return ret;
290335}
#define assert(x)
Definition duckdb.cpp:486071

◆ send() [2/2]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::send ( const Request & req)
inline
290447 {
290448 auto req2 = req;
290449 return send_(std::move(req2));
290450}

◆ stop()

void CPPHTTPLIB_NAMESPACE::ClientImpl::stop ( )
inline
291874 {
291875 std::lock_guard<std::mutex> guard(socket_mutex_);
291876
291877 // If there is anything ongoing right now, the ONLY thread-safe thing we can
291878 // do is to shutdown_socket, so that threads using this socket suddenly
291879 // discover they can't read/write any more and error out. Everything else
291880 // (closing the socket, shutting ssl down) is unsafe because these actions
291881 // are not thread-safe.
291882 if (socket_requests_in_flight_ > 0) {
291883 shutdown_socket(socket_);
291884
291885 // Aside from that, we set a flag for the socket to be closed when we're
291886 // done.
291887 socket_should_be_closed_when_request_is_done_ = true;
291888 return;
291889 }
291890
291891 // Otherwise, still holding the mutex, we can shut everything down ourselves
291892 shutdown_ssl(socket_, true);
291893 shutdown_socket(socket_);
291894 close_socket(socket_);
291895}

◆ host()

std::string CPPHTTPLIB_NAMESPACE::ClientImpl::host ( ) const
inline
291897{ return host_; }

◆ port()

int CPPHTTPLIB_NAMESPACE::ClientImpl::port ( ) const
inline
291899{ return port_; }

◆ is_socket_open()

size_t CPPHTTPLIB_NAMESPACE::ClientImpl::is_socket_open ( ) const
inline
291901 {
291902 std::lock_guard<std::mutex> guard(socket_mutex_);
291903 return socket_.is_open();
291904}

◆ socket()

socket_t CPPHTTPLIB_NAMESPACE::ClientImpl::socket ( ) const
inline
291906{ return socket_.sock; }

◆ set_hostname_addr_map()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_hostname_addr_map ( std::map< std::string, std::string > addr_map)
inline
291952 {
291953 addr_map_ = std::move(addr_map);
291954}

◆ set_default_headers()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_default_headers ( Headers headers)
inline
291956 {
291957 default_headers_ = std::move(headers);
291958}

◆ set_header_writer()

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

◆ set_address_family()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_address_family ( int family)
inline
291965 {
291966 address_family_ = family;
291967}

◆ set_tcp_nodelay()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_tcp_nodelay ( bool on)
inline
291969{ tcp_nodelay_ = on; }

◆ set_ipv6_v6only()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_ipv6_v6only ( bool on)
inline
291971{ ipv6_v6only_ = on; }

◆ set_socket_options()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_socket_options ( SocketOptions socket_options)
inline
291973 {
291974 socket_options_ = std::move(socket_options);
291975}

◆ set_connection_timeout() [1/2]

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_connection_timeout ( time_t sec,
time_t usec = 0 )
inline
291908 {
291909 connection_timeout_sec_ = sec;
291910 connection_timeout_usec_ = usec;
291911}

◆ set_connection_timeout() [2/2]

template<class Rep, class Period>
void CPPHTTPLIB_NAMESPACE::ClientImpl::set_connection_timeout ( const std::chrono::duration< Rep, Period > & duration)
inline
283810 {
283811 detail::duration_to_sec_and_usec(duration, [&](time_t sec, time_t usec) {
283812 set_connection_timeout(sec, usec);
283813 });
283814}

◆ set_read_timeout() [1/2]

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_read_timeout ( time_t sec,
time_t usec = 0 )
inline
291913 {
291914 read_timeout_sec_ = sec;
291915 read_timeout_usec_ = usec;
291916}

◆ set_read_timeout() [2/2]

template<class Rep, class Period>
void CPPHTTPLIB_NAMESPACE::ClientImpl::set_read_timeout ( const std::chrono::duration< Rep, Period > & duration)
inline
283818 {
283819 detail::duration_to_sec_and_usec(
283820 duration, [&](time_t sec, time_t usec) { set_read_timeout(sec, usec); });
283821}

◆ set_write_timeout() [1/2]

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_write_timeout ( time_t sec,
time_t usec = 0 )
inline
291918 {
291919 write_timeout_sec_ = sec;
291920 write_timeout_usec_ = usec;
291921}

◆ set_write_timeout() [2/2]

template<class Rep, class Period>
void CPPHTTPLIB_NAMESPACE::ClientImpl::set_write_timeout ( const std::chrono::duration< Rep, Period > & duration)
inline
283825 {
283826 detail::duration_to_sec_and_usec(
283827 duration, [&](time_t sec, time_t usec) { set_write_timeout(sec, usec); });
283828}

◆ set_max_timeout() [1/2]

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_max_timeout ( time_t msec)
inline
291923 {
291924 max_timeout_msec_ = msec;
291925}

◆ set_max_timeout() [2/2]

template<class Rep, class Period>
void CPPHTTPLIB_NAMESPACE::ClientImpl::set_max_timeout ( const std::chrono::duration< Rep, Period > & duration)
inline
283832 {
283833 auto msec =
283834 std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
283835 set_max_timeout(msec);
283836}

◆ set_basic_auth()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_basic_auth ( const std::string & username,
const std::string & password )
inline
291928 {
291929 basic_auth_username_ = username;
291930 basic_auth_password_ = password;
291931}

◆ set_bearer_token_auth()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_bearer_token_auth ( const std::string & token)
inline
291933 {
291934 bearer_token_auth_token_ = token;
291935}

◆ set_keep_alive()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_keep_alive ( bool on)
inline
291945{ keep_alive_ = on; }

◆ set_follow_location()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_follow_location ( bool on)
inline
291947{ follow_location_ = on; }

◆ set_path_encode()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_path_encode ( bool on)
inline
291949{ path_encode_ = on; }

◆ set_compress()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_compress ( bool on)
inline
291977{ compress_ = on; }

◆ set_decompress()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_decompress ( bool on)
inline
291979{ decompress_ = on; }

◆ set_interface()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_interface ( const std::string & intf)
inline
291981 {
291982 interface_ = intf;
291983}

◆ set_proxy()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_proxy ( const std::string & host,
int port )
inline
291985 {
291986 proxy_host_ = host;
291987 proxy_port_ = port;
291988}

◆ set_proxy_basic_auth()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_proxy_basic_auth ( const std::string & username,
const std::string & password )
inline
291991 {
291992 proxy_basic_auth_username_ = username;
291993 proxy_basic_auth_password_ = password;
291994}

◆ set_proxy_bearer_token_auth()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_proxy_bearer_token_auth ( const std::string & token)
inline
291996 {
291997 proxy_bearer_token_auth_token_ = token;
291998}

◆ set_logger()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_logger ( Logger logger)
inline
292057 {
292058 logger_ = std::move(logger);
292059}

◆ set_error_logger()

void CPPHTTPLIB_NAMESPACE::ClientImpl::set_error_logger ( ErrorLogger error_logger)
inline
292061 {
292062 error_logger_ = std::move(error_logger);
292063}

◆ create_and_connect_socket()

bool CPPHTTPLIB_NAMESPACE::ClientImpl::create_and_connect_socket ( Socket & socket,
Error & error )
inlineprotectedvirtual
290252 {
290253 auto sock = create_client_socket(error);
290254 if (sock == INVALID_SOCKET) { return false; }
290255 socket.sock = sock;
290256 return true;
290257}

◆ shutdown_ssl()

void CPPHTTPLIB_NAMESPACE::ClientImpl::shutdown_ssl ( Socket & socket,
bool shutdown_gracefully )
inlineprotectedvirtual
290260 {
290261 // If there are any requests in flight from threads other than us, then it's
290262 // a thread-unsafe race because individual ssl* objects are not thread-safe.
290263 assert(socket_requests_in_flight_ == 0 ||
290264 socket_requests_are_from_thread_ == std::this_thread::get_id());
290265}

◆ shutdown_socket()

void CPPHTTPLIB_NAMESPACE::ClientImpl::shutdown_socket ( Socket & socket) const
inlineprotected
290267 {
290268 if (socket.sock == INVALID_SOCKET) { return; }
290269 detail::shutdown_socket(socket.sock);
290270}

◆ close_socket()

void CPPHTTPLIB_NAMESPACE::ClientImpl::close_socket ( Socket & socket)
inlineprotected
290272 {
290273 // If there are requests in flight in another thread, usually closing
290274 // the socket will be fine and they will simply receive an error when
290275 // using the closed socket, but it is still a bug since rarely the OS
290276 // may reassign the socket id to be used for a new socket, and then
290277 // suddenly they will be operating on a live socket that is different
290278 // than the one they intended!
290279 assert(socket_requests_in_flight_ == 0 ||
290280 socket_requests_are_from_thread_ == std::this_thread::get_id());
290281
290282 // It is also a bug if this happens while SSL is still active
290283#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
290284 assert(socket.ssl == nullptr);
290285#endif
290286 if (socket.sock == INVALID_SOCKET) { return; }
290287 detail::close_socket(socket.sock);
290288 socket.sock = INVALID_SOCKET;
290289}

◆ process_request()

bool CPPHTTPLIB_NAMESPACE::ClientImpl::process_request ( Stream & strm,
Request & req,
Response & res,
bool close_connection,
Error & error )
inlineprotected
291062 {
291063 // Send request
291064 if (!write_request(strm, req, close_connection, error)) { return false; }
291065
291066#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
291067 if (is_ssl()) {
291068 auto is_proxy_enabled = !proxy_host_.empty() && proxy_port_ != -1;
291069 if (!is_proxy_enabled) {
291070 if (detail::is_ssl_peer_could_be_closed(socket_.ssl, socket_.sock)) {
291071 error = Error::SSLPeerCouldBeClosed_;
291072 output_error_log(error, &req);
291073 return false;
291074 }
291075 }
291076 }
291077#endif
291078
291079 // Receive response and headers
291080 if (!read_response_line(strm, req, res) ||
291081 !detail::read_headers(strm, res.headers)) {
291082 error = Error::Read;
291083 output_error_log(error, &req);
291084 return false;
291085 }
291086
291087 // Body
291088 if ((res.status != StatusCode::NoContent_204) && req.method != "HEAD" &&
291089 req.method != "CONNECT") {
291090 auto redirect = 300 < res.status && res.status < 400 &&
291091 res.status != StatusCode::NotModified_304 &&
291092 follow_location_;
291093
291094 if (req.response_handler && !redirect) {
291095 if (!req.response_handler(res)) {
291096 error = Error::Canceled;
291097 output_error_log(error, &req);
291098 return false;
291099 }
291100 }
291101
291102 auto out =
291103 req.content_receiver
291104 ? static_cast<ContentReceiverWithProgress>(
291105 [&](const char *buf, size_t n, size_t off, size_t len) {
291106 if (redirect) { return true; }
291107 auto ret = req.content_receiver(buf, n, off, len);
291108 if (!ret) {
291109 error = Error::Canceled;
291110 output_error_log(error, &req);
291111 }
291112 return ret;
291113 })
291114 : static_cast<ContentReceiverWithProgress>(
291115 [&](const char *buf, size_t n, size_t /*off*/,
291116 size_t /*len*/) {
291117 assert(res.body.size() + n <= res.body.max_size());
291118 res.body.append(buf, n);
291119 return true;
291120 });
291121
291122 auto progress = [&](size_t current, size_t total) {
291123 if (!req.download_progress || redirect) { return true; }
291124 auto ret = req.download_progress(current, total);
291125 if (!ret) {
291126 error = Error::Canceled;
291127 output_error_log(error, &req);
291128 }
291129 return ret;
291130 };
291131
291132 if (res.has_header("Content-Length")) {
291133 if (!req.content_receiver) {
291134 auto len = res.get_header_value_u64("Content-Length");
291135 if (len > res.body.max_size()) {
291136 error = Error::Read;
291137 output_error_log(error, &req);
291138 return false;
291139 }
291140 res.body.reserve(static_cast<size_t>(len));
291141 }
291142 }
291143
291144 if (res.status != StatusCode::NotModified_304) {
291145 int dummy_status;
291146 if (!detail::read_content(strm, res, (std::numeric_limits<size_t>::max)(),
291147 dummy_status, std::move(progress),
291148 std::move(out), decompress_)) {
291149 if (error != Error::Canceled) { error = Error::Read; }
291150 output_error_log(error, &req);
291151 return false;
291152 }
291153 }
291154 }
291155
291156 // Log
291157 output_log(req, res);
291158
291159 return true;
291160}

◆ write_content_with_provider()

bool CPPHTTPLIB_NAMESPACE::ClientImpl::write_content_with_provider ( Stream & strm,
const Request & req,
Error & error ) const
inlineprotected
290738 {
290739 auto is_shutting_down = []() { return false; };
290740
290741 if (req.is_chunked_content_provider_) {
290742 // TODO: Brotli support
290743 duckdb::unique_ptr<detail::compressor> compressor;
290744#ifdef CPPHTTPLIB_ZLIB_SUPPORT
290745 if (compress_) {
290746 compressor = detail::make_unique<detail::gzip_compressor>();
290747 } else
290748#endif
290749 {
290750 compressor = detail::make_unique<detail::nocompressor>();
290751 }
290752
290753 return detail::write_content_chunked(strm, req.content_provider_,
290754 is_shutting_down, *compressor, error);
290755 } else {
290756 return detail::write_content_with_progress(
290757 strm, req.content_provider_, 0, req.content_length_, is_shutting_down,
290758 req.upload_progress, error);
290759 }
290760}

◆ copy_settings()

void CPPHTTPLIB_NAMESPACE::ClientImpl::copy_settings ( const ClientImpl & rhs)
inlineprotected
290181 {
290182 client_cert_path_ = rhs.client_cert_path_;
290183 client_key_path_ = rhs.client_key_path_;
290184 connection_timeout_sec_ = rhs.connection_timeout_sec_;
290185 read_timeout_sec_ = rhs.read_timeout_sec_;
290186 read_timeout_usec_ = rhs.read_timeout_usec_;
290187 write_timeout_sec_ = rhs.write_timeout_sec_;
290188 write_timeout_usec_ = rhs.write_timeout_usec_;
290189 max_timeout_msec_ = rhs.max_timeout_msec_;
290190 basic_auth_username_ = rhs.basic_auth_username_;
290191 basic_auth_password_ = rhs.basic_auth_password_;
290192 bearer_token_auth_token_ = rhs.bearer_token_auth_token_;
290193#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
290194 digest_auth_username_ = rhs.digest_auth_username_;
290195 digest_auth_password_ = rhs.digest_auth_password_;
290196#endif
290197 keep_alive_ = rhs.keep_alive_;
290198 follow_location_ = rhs.follow_location_;
290199 path_encode_ = rhs.path_encode_;
290200 address_family_ = rhs.address_family_;
290201 tcp_nodelay_ = rhs.tcp_nodelay_;
290202 ipv6_v6only_ = rhs.ipv6_v6only_;
290203 socket_options_ = rhs.socket_options_;
290204 compress_ = rhs.compress_;
290205 decompress_ = rhs.decompress_;
290206 interface_ = rhs.interface_;
290207 proxy_host_ = rhs.proxy_host_;
290208 proxy_port_ = rhs.proxy_port_;
290209 proxy_basic_auth_username_ = rhs.proxy_basic_auth_username_;
290210 proxy_basic_auth_password_ = rhs.proxy_basic_auth_password_;
290211 proxy_bearer_token_auth_token_ = rhs.proxy_bearer_token_auth_token_;
290212#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
290213 proxy_digest_auth_username_ = rhs.proxy_digest_auth_username_;
290214 proxy_digest_auth_password_ = rhs.proxy_digest_auth_password_;
290215#endif
290216#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
290217 ca_cert_file_path_ = rhs.ca_cert_file_path_;
290218 ca_cert_dir_path_ = rhs.ca_cert_dir_path_;
290219 ca_cert_store_ = rhs.ca_cert_store_;
290220#endif
290221#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
290222 server_certificate_verification_ = rhs.server_certificate_verification_;
290223 server_hostname_verification_ = rhs.server_hostname_verification_;
290224 server_certificate_verifier_ = rhs.server_certificate_verifier_;
290225#endif
290226 logger_ = rhs.logger_;
290227 error_logger_ = rhs.error_logger_;
290228}

◆ output_log()

void CPPHTTPLIB_NAMESPACE::ClientImpl::output_log ( const Request & req,
const Response & res ) const
inlineprotected
291045 {
291046 if (logger_) {
291047 std::lock_guard<std::mutex> guard(logger_mutex_);
291048 logger_(req, res);
291049 }
291050}

◆ output_error_log()

void CPPHTTPLIB_NAMESPACE::ClientImpl::output_error_log ( const Error & err,
const Request * req ) const
inlineprotected
291053 {
291054 if (error_logger_) {
291055 std::lock_guard<std::mutex> guard(logger_mutex_);
291056 error_logger_(err, req);
291057 }
291058}

◆ send_() [1/2]

bool CPPHTTPLIB_NAMESPACE::ClientImpl::send_ ( Request & req,
Response & res,
Error & error )
inlineprivate
290337 {
290338 {
290339 std::lock_guard<std::mutex> guard(socket_mutex_);
290340
290341 // Set this to false immediately - if it ever gets set to true by the end
290342 // of the request, we know another thread instructed us to close the
290343 // socket.
290344 socket_should_be_closed_when_request_is_done_ = false;
290345
290346 auto is_alive = false;
290347 if (socket_.is_open()) {
290348 is_alive = detail::is_socket_alive(socket_.sock);
290349
290350#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
290351 if (is_alive && is_ssl()) {
290352 if (detail::is_ssl_peer_could_be_closed(socket_.ssl, socket_.sock)) {
290353 is_alive = false;
290354 }
290355 }
290356#endif
290357
290358 if (!is_alive) {
290359 // Attempt to avoid sigpipe by shutting down non-gracefully if it
290360 // seems like the other side has already closed the connection Also,
290361 // there cannot be any requests in flight from other threads since we
290362 // locked request_mutex_, so safe to close everything immediately
290363 const bool shutdown_gracefully = false;
290364 shutdown_ssl(socket_, shutdown_gracefully);
290365 shutdown_socket(socket_);
290366 close_socket(socket_);
290367 }
290368 }
290369
290370 if (!is_alive) {
290371 if (!create_and_connect_socket(socket_, error)) {
290372 output_error_log(error, &req);
290373 return false;
290374 }
290375
290376#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
290377 // TODO: refactoring
290378 if (is_ssl()) {
290379 auto &scli = static_cast<SSLClient &>(*this);
290380 if (!proxy_host_.empty() && proxy_port_ != -1) {
290381 auto success = false;
290382 if (!scli.connect_with_proxy(socket_, req.start_time_, res, success,
290383 error)) {
290384 if (!success) { output_error_log(error, &req); }
290385 return success;
290386 }
290387 }
290388
290389 if (!scli.initialize_ssl(socket_, error)) {
290390 output_error_log(error, &req);
290391 return false;
290392 }
290393 }
290394#endif
290395 }
290396
290397 // Mark the current socket as being in use so that it cannot be closed by
290398 // anyone else while this request is ongoing, even though we will be
290399 // releasing the mutex.
290400 if (socket_requests_in_flight_ > 1) {
290401 assert(socket_requests_are_from_thread_ == std::this_thread::get_id());
290402 }
290403 socket_requests_in_flight_ += 1;
290404 socket_requests_are_from_thread_ = std::this_thread::get_id();
290405 }
290406
290407 for (const auto &header : default_headers_) {
290408 if (req.headers.find(header.first) == req.headers.end()) {
290409 req.headers.insert(header);
290410 }
290411 }
290412
290413 auto ret = false;
290414 auto close_connection = !keep_alive_;
290415
290416 auto se = detail::scope_exit([&]() {
290417 // Briefly lock mutex in order to mark that a request is no longer ongoing
290418 std::lock_guard<std::mutex> guard(socket_mutex_);
290419 socket_requests_in_flight_ -= 1;
290420 if (socket_requests_in_flight_ <= 0) {
290421 assert(socket_requests_in_flight_ == 0);
290422 socket_requests_are_from_thread_ = std::thread::id();
290423 }
290424
290425 if (socket_should_be_closed_when_request_is_done_ || close_connection ||
290426 !ret) {
290427 shutdown_ssl(socket_, true);
290428 shutdown_socket(socket_);
290429 close_socket(socket_);
290430 }
290431 });
290432
290433 ret = process_socket(socket_, req.start_time_, [&](Stream &strm) {
290434 return handle_request(strm, req, res, close_connection, error);
290435 });
290436
290437 if (!ret) {
290438 if (error == Error::Success) {
290439 error = Error::Unknown;
290440 output_error_log(error, &req);
290441 }
290442 }
290443
290444 return ret;
290445}

◆ send_() [2/2]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::send_ ( Request && req)
inlineprivate
290452 {
290453 auto res = detail::make_unique<Response>();
290454 auto error = Error::Success;
290455 auto ret = send(req, *res, error);
290456#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
290457 return Result{ret ? std::move(res) : nullptr, error, std::move(req.headers),
290458 last_ssl_error_, last_openssl_error_};
290459#else
290460 return Result{ret ? std::move(res) : nullptr, error, std::move(req.headers)};
290461#endif
290462}

◆ create_client_socket()

socket_t CPPHTTPLIB_NAMESPACE::ClientImpl::create_client_socket ( Error & error) const
inlineprivate
290230 {
290231 if (!proxy_host_.empty() && proxy_port_ != -1) {
290232 return detail::create_client_socket(
290233 proxy_host_, std::string(), proxy_port_, address_family_, tcp_nodelay_,
290234 ipv6_v6only_, socket_options_, connection_timeout_sec_,
290235 connection_timeout_usec_, read_timeout_sec_, read_timeout_usec_,
290236 write_timeout_sec_, write_timeout_usec_, interface_, error);
290237 }
290238
290239 // Check is custom IP specified for host_
290240 std::string ip;
290241 auto it = addr_map_.find(host_);
290242 if (it != addr_map_.end()) { ip = it->second; }
290243
290244 return detail::create_client_socket(
290245 host_, ip, port_, address_family_, tcp_nodelay_, ipv6_v6only_,
290246 socket_options_, connection_timeout_sec_, connection_timeout_usec_,
290247 read_timeout_sec_, read_timeout_usec_, write_timeout_sec_,
290248 write_timeout_usec_, interface_, error);
290249}

◆ read_response_line()

bool CPPHTTPLIB_NAMESPACE::ClientImpl::read_response_line ( Stream & strm,
const Request & req,
Response & res ) const
inlineprivate
290292 {
290293 std::array<char, 2048> buf{};
290294
290295 detail::stream_line_reader line_reader(strm, buf.data(), buf.size());
290296
290297 if (!line_reader.getline()) { return false; }
290298
290299#ifdef CPPHTTPLIB_ALLOW_LF_AS_LINE_TERMINATOR
290300 REGEX_SCOPE const Regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r?\n");
290301#else
290302 REGEX_SCOPE const Regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r\n");
290303#endif
290304
290305 Match m;
290306 if (!RegexMatch(line_reader.ptr(), m, re)) {
290307 return req.method == "CONNECT";
290308 }
290309 res.version = std::string(m[1]);
290310 res.status = std::stoi(std::string(m[2]));
290311 res.reason = std::string(m[3]);
290312
290313 // Ignore '100 Continue'
290314 while (res.status == StatusCode::Continue_100) {
290315 if (!line_reader.getline()) { return false; } // CRLF
290316 if (!line_reader.getline()) { return false; } // next response line
290317
290318 if (!RegexMatch(line_reader.ptr(), m, re)) { return false; }
290319 res.version = std::string(m[1]);
290320 res.status = std::stoi(std::string(m[2]));
290321 res.reason = std::string(m[3]);
290322 }
290323
290324 return true;
290325}
Match(int x, int y, float similarity, const String &class_id, int template_id)

◆ write_request()

bool CPPHTTPLIB_NAMESPACE::ClientImpl::write_request ( Stream & strm,
Request & req,
bool close_connection,
Error & error )
inlineprivate
290763 {
290764 // Prepare additional headers
290765 if (close_connection) {
290766 if (!req.has_header("Connection")) {
290767 req.set_header("Connection", "close");
290768 }
290769 }
290770
290771 if (!req.has_header("Host")) {
290772 // For Unix socket connections, use "localhost" as Host header (similar to
290773 // curl behavior)
290774 if (address_family_ == AF_UNIX) {
290775 req.set_header("Host", "localhost");
290776 } else {
290777 req.set_header("Host", host_and_port_);
290778 }
290779 }
290780
290781 if (!req.has_header("Accept")) { req.set_header("Accept", "*/*"); }
290782
290783 if (!req.content_receiver) {
290784 if (!req.has_header("Accept-Encoding")) {
290785 std::string accept_encoding;
290786#ifdef CPPHTTPLIB_BROTLI_SUPPORT
290787 accept_encoding = "br";
290788#endif
290789#ifdef CPPHTTPLIB_ZLIB_SUPPORT
290790 if (!accept_encoding.empty()) { accept_encoding += ", "; }
290791 accept_encoding += "gzip, deflate";
290792#endif
290793#ifdef CPPHTTPLIB_ZSTD_SUPPORT
290794 if (!accept_encoding.empty()) { accept_encoding += ", "; }
290795 accept_encoding += "zstd";
290796#endif
290797 req.set_header("Accept-Encoding", accept_encoding);
290798 }
290799
290800#ifndef CPPHTTPLIB_NO_DEFAULT_USER_AGENT
290801 if (!req.has_header("User-Agent")) {
290802 auto agent = std::string("cpp-httplib/") + CPPHTTPLIB_VERSION;
290803 req.set_header("User-Agent", agent);
290804 }
290805#endif
290806 };
290807
290808 if (req.body.empty()) {
290809 if (req.content_provider_) {
290810 if (!req.is_chunked_content_provider_) {
290811 if (!req.has_header("Content-Length")) {
290812 auto length = std::to_string(req.content_length_);
290813 req.set_header("Content-Length", length);
290814 }
290815 }
290816 } else {
290817 if (req.method == "POST" || req.method == "PUT" ||
290818 req.method == "PATCH") {
290819 req.set_header("Content-Length", "0");
290820 }
290821 }
290822 } else {
290823 if (!req.has_header("Content-Type")) {
290824 req.set_header("Content-Type", "text/plain");
290825 }
290826
290827 if (!req.has_header("Content-Length")) {
290828 auto length = std::to_string(req.body.size());
290829 req.set_header("Content-Length", length);
290830 }
290831 }
290832
290833 if (!basic_auth_password_.empty() || !basic_auth_username_.empty()) {
290834 if (!req.has_header("Authorization")) {
290835 req.headers.insert(make_basic_authentication_header(
290836 basic_auth_username_, basic_auth_password_, false));
290837 }
290838 }
290839
290840 if (!proxy_basic_auth_username_.empty() &&
290841 !proxy_basic_auth_password_.empty()) {
290842 if (!req.has_header("Proxy-Authorization")) {
290843 req.headers.insert(make_basic_authentication_header(
290844 proxy_basic_auth_username_, proxy_basic_auth_password_, true));
290845 }
290846 }
290847
290848 if (!bearer_token_auth_token_.empty()) {
290849 if (!req.has_header("Authorization")) {
290850 req.headers.insert(make_bearer_token_authentication_header(
290851 bearer_token_auth_token_, false));
290852 }
290853 }
290854
290855 if (!proxy_bearer_token_auth_token_.empty()) {
290856 if (!req.has_header("Proxy-Authorization")) {
290857 req.headers.insert(make_bearer_token_authentication_header(
290858 proxy_bearer_token_auth_token_, true));
290859 }
290860 }
290861
290862 // Request line and headers
290863 {
290864 detail::BufferStream bstrm;
290865
290866 // Extract path and query from req.path
290867 std::string path_part, query_part;
290868 auto query_pos = req.path.find('?');
290869 if (query_pos != std::string::npos) {
290870 path_part = req.path.substr(0, query_pos);
290871 query_part = req.path.substr(query_pos + 1);
290872 } else {
290873 path_part = req.path;
290874 query_part = "";
290875 }
290876
290877 // Encode path and query
290878 auto path_with_query =
290879 path_encode_ ? detail::encode_path(path_part) : path_part;
290880
290881 detail::parse_query_text(query_part, req.params);
290882 if (!req.params.empty()) {
290883 path_with_query = append_query_params(path_with_query, req.params);
290884 }
290885
290886 // Write request line and headers
290887 detail::write_request_line(bstrm, req.method, path_with_query);
290888 header_writer_(bstrm, req.headers);
290889
290890 // Flush buffer
290891 auto &data = bstrm.get_buffer();
290892 if (!detail::write_data(strm, data.data(), data.size())) {
290893 error = Error::Write;
290894 output_error_log(error, &req);
290895 return false;
290896 }
290897 }
290898
290899 // Body
290900 if (req.body.empty()) {
290901 return write_content_with_provider(strm, req, error);
290902 }
290903
290904 if (req.upload_progress) {
290905 auto body_size = req.body.size();
290906 size_t written = 0;
290907 auto data = req.body.data();
290908
290909 while (written < body_size) {
290910 size_t to_write = (std::min)(CPPHTTPLIB_SEND_BUFSIZ, body_size - written);
290911 if (!detail::write_data(strm, data + written, to_write)) {
290912 error = Error::Write;
290913 output_error_log(error, &req);
290914 return false;
290915 }
290916 written += to_write;
290917
290918 if (!req.upload_progress(written, body_size)) {
290919 error = Error::Canceled;
290920 output_error_log(error, &req);
290921 return false;
290922 }
290923 }
290924 } else {
290925 if (!detail::write_data(strm, req.body.data(), req.body.size())) {
290926 error = Error::Write;
290927 output_error_log(error, &req);
290928 return false;
290929 }
290930 }
290931
290932 return true;
290933}

◆ redirect()

bool CPPHTTPLIB_NAMESPACE::ClientImpl::redirect ( Request & req,
Response & res,
Error & error )
inlineprivate
290542 {
290543 if (req.redirect_count_ == 0) {
290544 error = Error::ExceedRedirectCount;
290545 output_error_log(error, &req);
290546 return false;
290547 }
290548
290549 auto location = res.get_header_value("location");
290550 if (location.empty()) {
290551 // s3 requests will not return a location header, and instead a
290552 // X-Amx-Region-Bucket header. Return true so all response headers
290553 // are returned to the httpfs/calling extension
290554 return true;
290555 }
290556
290557 REGEX_SCOPE const Regex re(
290558 R"((?:(https?):)?(?://(?:\‍[([a-fA-F\d:]+)\‍]|([^:/?#]+))(?::(\d+))?)?([^?#]*)(\?[^#]*)?(?:#.*)?)");
290559
290560 Match m;
290561 if (!RegexMatch(location, m, re)) { return false; }
290562
290563 auto scheme = is_ssl() ? "https" : "http";
290564
290565 auto next_scheme = m[1].str();
290566 auto next_host = m[2].str();
290567 if (next_host.empty()) { next_host = m[3].str(); }
290568 auto port_str = m[4].str();
290569 auto next_path = m[5].str();
290570 auto next_query = m[6].str();
290571
290572 auto next_port = port_;
290573 if (!port_str.empty()) {
290574 next_port = std::stoi(port_str);
290575 } else if (!next_scheme.empty()) {
290576 next_port = next_scheme == "https" ? 443 : 80;
290577 }
290578
290579 if (next_scheme.empty()) { next_scheme = scheme; }
290580 if (next_host.empty()) { next_host = host_; }
290581 if (next_path.empty()) { next_path = "/"; }
290582
290583 auto path = decode_query_component(next_path, true) + next_query;
290584
290585 // Same host redirect - use current client
290586 if (next_scheme == scheme && next_host == host_ && next_port == port_) {
290587 return detail::redirect(*this, req, res, path, location, error);
290588 }
290589
290590 // Cross-host/scheme redirect - create new client with robust setup
290591 return create_redirect_client(next_scheme, next_host, next_port, req, res,
290592 path, location, error);
290593}

◆ create_redirect_client()

bool CPPHTTPLIB_NAMESPACE::ClientImpl::create_redirect_client ( const std::string & scheme,
const std::string & host,
int port,
Request & req,
Response & res,
const std::string & path,
const std::string & location,
Error & error )
inlineprivate
290599 {
290600 // Determine if we need SSL
290601 auto need_ssl = (scheme == "https");
290602
290603 // Clean up request headers that are host/client specific
290604 // Remove headers that should not be carried over to new host
290605 auto headers_to_remove =
290606 std::vector<std::string>{"Host", "Proxy-Authorization", "Authorization"};
290607
290608 for (const auto &header_name : headers_to_remove) {
290609 auto it = req.headers.find(header_name);
290610 while (it != req.headers.end()) {
290611 it = req.headers.erase(it);
290612 it = req.headers.find(header_name);
290613 }
290614 }
290615
290616 // Create appropriate client type and handle redirect
290617 if (need_ssl) {
290618#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
290619 // Create SSL client for HTTPS redirect
290620 SSLClient redirect_client(host, port);
290621
290622 // Setup basic client configuration first
290623 setup_redirect_client(redirect_client);
290624
290625 // SSL-specific configuration for proxy environments
290626 if (!proxy_host_.empty() && proxy_port_ != -1) {
290627 // Critical: Disable SSL verification for proxy environments
290628 redirect_client.enable_server_certificate_verification(false);
290629 redirect_client.enable_server_hostname_verification(false);
290630 } else {
290631 // For direct SSL connections, copy SSL verification settings
290632 redirect_client.enable_server_certificate_verification(
290633 server_certificate_verification_);
290634 redirect_client.enable_server_hostname_verification(
290635 server_hostname_verification_);
290636 }
290637
290638 // Handle CA certificate store and paths if available
290639 if (ca_cert_store_ && X509_STORE_up_ref(ca_cert_store_)) {
290640 redirect_client.set_ca_cert_store(ca_cert_store_);
290641 }
290642 if (!ca_cert_file_path_.empty()) {
290643 redirect_client.set_ca_cert_path(ca_cert_file_path_, ca_cert_dir_path_);
290644 }
290645
290646 // Client certificates are set through constructor for SSLClient
290647 // NOTE: SSLClient constructor already takes client_cert_path and
290648 // client_key_path so we need to create it properly if client certs are
290649 // needed
290650
290651 // Execute the redirect
290652 return detail::redirect(redirect_client, req, res, path, location, error);
290653#else
290654 // SSL not supported - set appropriate error
290655 error = Error::SSLConnection;
290656 output_error_log(error, &req);
290657 return false;
290658#endif
290659 } else {
290660 // HTTP redirect
290661 ClientImpl redirect_client(host, port);
290662
290663 // Setup client with robust configuration
290664 setup_redirect_client(redirect_client);
290665
290666 // Execute the redirect
290667 return detail::redirect(redirect_client, req, res, path, location, error);
290668 }
290669}

◆ setup_redirect_client()

template<typename ClientType>
void CPPHTTPLIB_NAMESPACE::ClientImpl::setup_redirect_client ( ClientType & client)
inlineprivate
290674 {
290675 // Copy basic settings first
290676 client.set_connection_timeout(connection_timeout_sec_);
290677 client.set_read_timeout(read_timeout_sec_, read_timeout_usec_);
290678 client.set_write_timeout(write_timeout_sec_, write_timeout_usec_);
290679 client.set_keep_alive(keep_alive_);
290680 client.set_follow_location(
290681 true); // Enable redirects to handle multi-step redirects
290682 client.set_path_encode(path_encode_);
290683 client.set_compress(compress_);
290684 client.set_decompress(decompress_);
290685
290686 // Copy authentication settings BEFORE proxy setup
290687 if (!basic_auth_username_.empty()) {
290688 client.set_basic_auth(basic_auth_username_, basic_auth_password_);
290689 }
290690 if (!bearer_token_auth_token_.empty()) {
290691 client.set_bearer_token_auth(bearer_token_auth_token_);
290692 }
290693#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
290694 if (!digest_auth_username_.empty()) {
290695 client.set_digest_auth(digest_auth_username_, digest_auth_password_);
290696 }
290697#endif
290698
290699 // Setup proxy configuration (CRITICAL ORDER - proxy must be set
290700 // before proxy auth)
290701 if (!proxy_host_.empty() && proxy_port_ != -1) {
290702 // First set proxy host and port
290703 client.set_proxy(proxy_host_, proxy_port_);
290704
290705 // Then set proxy authentication (order matters!)
290706 if (!proxy_basic_auth_username_.empty()) {
290707 client.set_proxy_basic_auth(proxy_basic_auth_username_,
290708 proxy_basic_auth_password_);
290709 }
290710 if (!proxy_bearer_token_auth_token_.empty()) {
290711 client.set_proxy_bearer_token_auth(proxy_bearer_token_auth_token_);
290712 }
290713#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
290714 if (!proxy_digest_auth_username_.empty()) {
290715 client.set_proxy_digest_auth(proxy_digest_auth_username_,
290716 proxy_digest_auth_password_);
290717 }
290718#endif
290719 }
290720
290721 // Copy network and socket settings
290722 client.set_address_family(address_family_);
290723 client.set_tcp_nodelay(tcp_nodelay_);
290724 client.set_ipv6_v6only(ipv6_v6only_);
290725 if (socket_options_) { client.set_socket_options(socket_options_); }
290726 if (!interface_.empty()) { client.set_interface(interface_); }
290727
290728 // Copy logging and headers
290729 if (logger_) { client.set_logger(logger_); }
290730 if (error_logger_) { client.set_error_logger(error_logger_); }
290731
290732 // NOTE: DO NOT copy default_headers_ as they may contain stale Host headers
290733 // Each new client should generate its own headers based on its target host
290734}

◆ handle_request()

bool CPPHTTPLIB_NAMESPACE::ClientImpl::handle_request ( Stream & strm,
Request & req,
Response & res,
bool close_connection,
Error & error )
inlineprivate
290466 {
290467 if (req.path.empty()) {
290468 error = Error::Connection;
290469 output_error_log(error, &req);
290470 return false;
290471 }
290472
290473 auto req_save = req;
290474
290475 bool ret;
290476
290477 if (!is_ssl() && !proxy_host_.empty() && proxy_port_ != -1) {
290478 auto req2 = req;
290479 req2.path = "http://" + host_and_port_ + req.path;
290480 ret = process_request(strm, req2, res, close_connection, error);
290481 req = req2;
290482 req.path = req_save.path;
290483 } else {
290484 ret = process_request(strm, req, res, close_connection, error);
290485 }
290486
290487 if (!ret) { return false; }
290488
290489 if (res.get_header_value("Connection") == "close" ||
290490 (res.version == "HTTP/1.0" && res.reason != "Connection established")) {
290491 // TODO this requires a not-entirely-obvious chain of calls to be correct
290492 // for this to be safe.
290493
290494 // This is safe to call because handle_request is only called by send_
290495 // which locks the request mutex during the process. It would be a bug
290496 // to call it from a different thread since it's a thread-safety issue
290497 // to do these things to the socket if another thread is using the socket.
290498 std::lock_guard<std::mutex> guard(socket_mutex_);
290499 shutdown_ssl(socket_, true);
290500 shutdown_socket(socket_);
290501 close_socket(socket_);
290502 }
290503
290504 if (300 < res.status && res.status < 400 && follow_location_) {
290505 req = req_save;
290506 ret = redirect(req, res, error);
290507 }
290508
290509#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
290510 if ((res.status == StatusCode::Unauthorized_401 ||
290511 res.status == StatusCode::ProxyAuthenticationRequired_407) &&
290512 req.authorization_count_ < 5) {
290513 auto is_proxy = res.status == StatusCode::ProxyAuthenticationRequired_407;
290514 const auto &username =
290515 is_proxy ? proxy_digest_auth_username_ : digest_auth_username_;
290516 const auto &password =
290517 is_proxy ? proxy_digest_auth_password_ : digest_auth_password_;
290518
290519 if (!username.empty() && !password.empty()) {
290520 std::map<std::string, std::string> auth;
290521 if (detail::parse_www_authenticate(res, auth, is_proxy)) {
290522 Request new_req = req;
290523 new_req.authorization_count_ += 1;
290524 new_req.headers.erase(is_proxy ? "Proxy-Authorization"
290525 : "Authorization");
290526 new_req.headers.insert(detail::make_digest_authentication_header(
290527 req, auth, new_req.authorization_count_, detail::random_string(10),
290528 username, password, is_proxy));
290529
290530 Response new_res;
290531
290532 ret = send(new_req, new_res, error);
290533 if (ret) { res = new_res; }
290534 }
290535 }
290536 }
290537#endif
290538
290539 return ret;
290540}

◆ send_with_content_provider() [1/2]

duckdb::unique_ptr< Response > CPPHTTPLIB_NAMESPACE::ClientImpl::send_with_content_provider ( Request & req,
const char * body,
size_t content_length,
ContentProvider content_provider,
ContentProviderWithoutLength content_provider_without_length,
const std::string & content_type,
Error & error )
inlineprivate
290939 {
290940 if (!content_type.empty()) { req.set_header("Content-Type", content_type); }
290941
290942#ifdef CPPHTTPLIB_ZLIB_SUPPORT
290943 if (compress_) { req.set_header("Content-Encoding", "gzip"); }
290944#endif
290945
290946#ifdef CPPHTTPLIB_ZLIB_SUPPORT
290947 if (compress_ && !content_provider_without_length) {
290948 // TODO: Brotli support
290949 detail::gzip_compressor compressor;
290950
290951 if (content_provider) {
290952 auto ok = true;
290953 size_t offset = 0;
290954 DataSink data_sink;
290955
290956 data_sink.write = [&](const char *data, size_t data_len) -> bool {
290957 if (ok) {
290958 auto last = offset + data_len == content_length;
290959
290960 auto ret = compressor.compress(
290961 data, data_len, last,
290962 [&](const char *compressed_data, size_t compressed_data_len) {
290963 req.body.append(compressed_data, compressed_data_len);
290964 return true;
290965 });
290966
290967 if (ret) {
290968 offset += data_len;
290969 } else {
290970 ok = false;
290971 }
290972 }
290973 return ok;
290974 };
290975
290976 while (ok && offset < content_length) {
290977 if (!content_provider(offset, content_length - offset, data_sink)) {
290978 error = Error::Canceled;
290979 output_error_log(error, &req);
290980 return nullptr;
290981 }
290982 }
290983 } else {
290984 if (!compressor.compress(body, content_length, true,
290985 [&](const char *data, size_t data_len) {
290986 req.body.append(data, data_len);
290987 return true;
290988 })) {
290989 error = Error::Compression;
290990 output_error_log(error, &req);
290991 return nullptr;
290992 }
290993 }
290994 } else
290995#endif
290996 {
290997 if (content_provider) {
290998 req.content_length_ = content_length;
290999 req.content_provider_ = std::move(content_provider);
291000 req.is_chunked_content_provider_ = false;
291001 } else if (content_provider_without_length) {
291002 req.content_length_ = 0;
291003 req.content_provider_ = detail::ContentProviderAdapter(
291004 std::move(content_provider_without_length));
291005 req.is_chunked_content_provider_ = true;
291006 req.set_header("Transfer-Encoding", "chunked");
291007 } else {
291008 req.body.assign(body, content_length);
291009 }
291010 }
291011
291012 auto res = detail::make_unique<Response>();
291013 return send(req, *res, error) ? std::move(res) : nullptr;
291014}

◆ send_with_content_provider() [2/2]

Result CPPHTTPLIB_NAMESPACE::ClientImpl::send_with_content_provider ( const std::string & method,
const std::string & path,
const Headers & headers,
const char * body,
size_t content_length,
ContentProvider content_provider,
ContentProviderWithoutLength content_provider_without_length,
const std::string & content_type,
UploadProgress progress )
inlineprivate
291020 {
291021 Request req;
291022 req.method = method;
291023 req.headers = headers;
291024 req.path = path;
291025 req.upload_progress = std::move(progress);
291026 if (max_timeout_msec_ > 0) {
291027 req.start_time_ = std::chrono::steady_clock::now();
291028 }
291029
291030 auto error = Error::Success;
291031
291032 auto res = send_with_content_provider(
291033 req, body, content_length, std::move(content_provider),
291034 std::move(content_provider_without_length), content_type, error);
291035
291036#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
291037 return Result{std::move(res), error, std::move(req.headers), last_ssl_error_,
291038 last_openssl_error_};
291039#else
291040 return Result{std::move(res), error, std::move(req.headers)};
291041#endif
291042}

◆ get_multipart_content_provider()

ContentProviderWithoutLength CPPHTTPLIB_NAMESPACE::ClientImpl::get_multipart_content_provider ( const std::string & boundary,
const UploadFormDataItems & items,
const FormDataProviderItems & provider_items ) const
inlineprivate
291164 {
291165 size_t cur_item = 0;
291166 size_t cur_start = 0;
291167 // cur_item and cur_start are copied to within the std::function and
291168 // maintain state between successive calls
291169 return [&, cur_item, cur_start](size_t offset,
291170 DataSink &sink) mutable -> bool {
291171 if (!offset && !items.empty()) {
291172 sink.os << detail::serialize_multipart_formdata(items, boundary, false);
291173 return true;
291174 } else if (cur_item < provider_items.size()) {
291175 if (!cur_start) {
291176 const auto &begin = detail::serialize_multipart_formdata_item_begin(
291177 provider_items[cur_item], boundary);
291178 offset += begin.size();
291179 cur_start = offset;
291180 sink.os << begin;
291181 }
291182
291183 DataSink cur_sink;
291184 auto has_data = true;
291185 cur_sink.write = sink.write;
291186 cur_sink.done = [&]() { has_data = false; };
291187
291188 if (!provider_items[cur_item].provider(offset - cur_start, cur_sink)) {
291189 return false;
291190 }
291191
291192 if (!has_data) {
291193 sink.os << detail::serialize_multipart_formdata_item_end();
291194 cur_item++;
291195 cur_start = 0;
291196 }
291197 return true;
291198 } else {
291199 sink.os << detail::serialize_multipart_formdata_finish(boundary);
291200 sink.done();
291201 return true;
291202 }
291203 };
291204}

◆ process_socket()

bool CPPHTTPLIB_NAMESPACE::ClientImpl::process_socket ( const Socket & socket,
std::chrono::time_point< std::chrono::steady_clock > start_time,
std::function< bool(Stream &strm)> callback )
inlineprivatevirtual
291209 {
291210 return detail::process_client_socket(
291211 socket.sock, read_timeout_sec_, read_timeout_usec_, write_timeout_sec_,
291212 write_timeout_usec_, max_timeout_msec_, start_time, std::move(callback));
291213}

◆ is_ssl()

bool CPPHTTPLIB_NAMESPACE::ClientImpl::is_ssl ( ) const
inlineprivatevirtual
291215{ return false; }

Member Data Documentation

◆ header_writer_

std::function<ssize_t(Stream &, Headers &)> CPPHTTPLIB_NAMESPACE::ClientImpl::header_writer_
protected
Initial value:
=
detail::write_headers

The documentation for this class was generated from the following file: