88#ifndef CPPHTTPLIB_HTTPLIB_H
99#define CPPHTTPLIB_HTTPLIB_H
1010
11- #define CPPHTTPLIB_VERSION " 0.38 .0"
12- #define CPPHTTPLIB_VERSION_NUM " 0x002600 "
11+ #define CPPHTTPLIB_VERSION " 0.39 .0"
12+ #define CPPHTTPLIB_VERSION_NUM " 0x002700 "
1313
1414#ifdef _WIN32
1515#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0A00
@@ -1001,8 +1001,8 @@ class DataSink {
10011001
10021002 protected:
10031003 std::streamsize xsputn (const char *s, std::streamsize n) override {
1004- sink_.write (s, static_cast <size_t >(n));
1005- return n ;
1004+ if ( sink_.write (s, static_cast <size_t >(n))) { return n; }
1005+ return 0 ;
10061006 }
10071007
10081008 private:
@@ -1058,9 +1058,12 @@ make_file_provider(const std::string &name, const std::string &filepath,
10581058
10591059inline std::pair<size_t , ContentProvider>
10601060make_file_body (const std::string &filepath) {
1061- std::ifstream f (filepath, std::ios::binary | std::ios::ate);
1062- if (!f) { return {0 , ContentProvider{}}; }
1063- auto size = static_cast <size_t >(f.tellg ());
1061+ size_t size = 0 ;
1062+ {
1063+ std::ifstream f (filepath, std::ios::binary | std::ios::ate);
1064+ if (!f) { return {0 , ContentProvider{}}; }
1065+ size = static_cast <size_t >(f.tellg ());
1066+ }
10641067
10651068 ContentProvider provider = [filepath](size_t offset, size_t length,
10661069 DataSink &sink) -> bool {
@@ -1882,7 +1885,8 @@ class Result {
18821885
18831886#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
18841887public:
1885- [[deprecated(" Use ssl_backend_error() instead" )]]
1888+ [[deprecated(" Use ssl_backend_error() instead. "
1889+ " This function will be removed by v1.0.0." )]]
18861890 uint64_t ssl_openssl_error () const {
18871891 return ssl_backend_error_;
18881892 }
@@ -2362,13 +2366,16 @@ class ClientImpl {
23622366
23632367#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
23642368public:
2365- [[deprecated(" Use load_ca_cert_store() instead" )]]
2369+ [[deprecated(" Use load_ca_cert_store() instead. "
2370+ " This function will be removed by v1.0.0." )]]
23662371 void set_ca_cert_store (X509_STORE *ca_cert_store);
23672372
2368- [[deprecated(" Use tls::create_ca_store() instead" )]]
2373+ [[deprecated(" Use tls::create_ca_store() instead. "
2374+ " This function will be removed by v1.0.0." )]]
23692375 X509_STORE *create_ca_cert_store (const char *ca_cert, std::size_t size) const ;
23702376
2371- [[deprecated(" Use set_server_certificate_verifier(VerifyCallback) instead" )]]
2377+ [[deprecated(" Use set_server_certificate_verifier(VerifyCallback) instead. "
2378+ " This function will be removed by v1.0.0." )]]
23722379 virtual void set_server_certificate_verifier (
23732380 std::function<SSLVerifierResponse(SSL *ssl)> verifier);
23742381#endif
@@ -2597,14 +2604,17 @@ class Client {
25972604
25982605#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
25992606public:
2600- [[deprecated(" Use tls_context() instead" )]]
2607+ [[deprecated(" Use tls_context() instead. "
2608+ " This function will be removed by v1.0.0." )]]
26012609 SSL_CTX *ssl_context () const ;
26022610
2603- [[deprecated(" Use set_session_verifier(session_t) instead" )]]
2611+ [[deprecated(" Use set_session_verifier(session_t) instead. "
2612+ " This function will be removed by v1.0.0." )]]
26042613 void set_server_certificate_verifier (
26052614 std::function<SSLVerifierResponse(SSL *ssl)> verifier);
26062615
2607- [[deprecated(" Use Result::ssl_backend_error() instead" )]]
2616+ [[deprecated(" Use Result::ssl_backend_error() instead. "
2617+ " This function will be removed by v1.0.0." )]]
26082618 long get_verify_result () const ;
26092619#endif
26102620};
@@ -2656,18 +2666,22 @@ class SSLServer : public Server {
26562666#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
26572667public:
26582668 [[deprecated(" Use SSLServer(PemMemory) or "
2659- " SSLServer(ContextSetupCallback) instead" )]]
2669+ " SSLServer(ContextSetupCallback) instead. "
2670+ " This constructor will be removed by v1.0.0." )]]
26602671 SSLServer (X509 *cert, EVP_PKEY *private_key,
26612672 X509_STORE *client_ca_cert_store = nullptr );
26622673
2663- [[deprecated(" Use SSLServer(ContextSetupCallback) instead" )]]
2674+ [[deprecated(" Use SSLServer(ContextSetupCallback) instead. "
2675+ " This constructor will be removed by v1.0.0." )]]
26642676 SSLServer (
26652677 const std::function<bool (SSL_CTX &ssl_ctx)> &setup_ssl_ctx_callback);
26662678
2667- [[deprecated(" Use tls_context() instead" )]]
2679+ [[deprecated(" Use tls_context() instead. "
2680+ " This function will be removed by v1.0.0." )]]
26682681 SSL_CTX *ssl_context () const ;
26692682
2670- [[deprecated(" Use update_certs_pem() instead" )]]
2683+ [[deprecated(" Use update_certs_pem() instead. "
2684+ " This function will be removed by v1.0.0." )]]
26712685 void update_certs (X509 *cert, EVP_PKEY *private_key,
26722686 X509_STORE *client_ca_cert_store = nullptr );
26732687#endif
@@ -2752,18 +2766,22 @@ class SSLClient final : public ClientImpl {
27522766
27532767#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
27542768public:
2755- [[deprecated(" Use SSLClient(host, port, PemMemory) instead" )]]
2769+ [[deprecated(" Use SSLClient(host, port, PemMemory) instead. "
2770+ " This constructor will be removed by v1.0.0." )]]
27562771 explicit SSLClient (const std::string &host, int port, X509 *client_cert,
27572772 EVP_PKEY *client_key,
27582773 const std::string &private_key_password = std::string());
27592774
2760- [[deprecated(" Use Result::ssl_backend_error() instead" )]]
2775+ [[deprecated(" Use Result::ssl_backend_error() instead. "
2776+ " This function will be removed by v1.0.0." )]]
27612777 long get_verify_result () const ;
27622778
2763- [[deprecated(" Use tls_context() instead" )]]
2779+ [[deprecated(" Use tls_context() instead. "
2780+ " This function will be removed by v1.0.0." )]]
27642781 SSL_CTX *ssl_context () const ;
27652782
2766- [[deprecated(" Use set_session_verifier(session_t) instead" )]]
2783+ [[deprecated(" Use set_session_verifier(session_t) instead. "
2784+ " This function will be removed by v1.0.0." )]]
27672785 void set_server_certificate_verifier (
27682786 std::function<SSLVerifierResponse(SSL *ssl)> verifier) override ;
27692787
@@ -3641,6 +3659,9 @@ class SSEClient {
36413659 SSEClient &set_reconnect_interval (int ms);
36423660 SSEClient &set_max_reconnect_attempts (int n);
36433661
3662+ // Update headers (thread-safe)
3663+ SSEClient &set_headers (const Headers &headers);
3664+
36443665 // State accessors
36453666 bool is_connected () const ;
36463667 const std::string &last_event_id () const ;
@@ -3665,6 +3686,7 @@ class SSEClient {
36653686 Client &client_;
36663687 std::string path_;
36673688 Headers headers_;
3689+ mutable std::mutex headers_mutex_;
36683690
36693691 // Callbacks
36703692 MessageHandler on_message_;
@@ -3785,6 +3807,12 @@ class WebSocketClient {
37853807 void set_read_timeout (time_t sec, time_t usec = 0 );
37863808 void set_write_timeout (time_t sec, time_t usec = 0 );
37873809 void set_websocket_ping_interval (time_t sec);
3810+ void set_tcp_nodelay (bool on);
3811+ void set_address_family (int family);
3812+ void set_ipv6_v6only (bool on);
3813+ void set_socket_options (SocketOptions socket_options);
3814+ void set_connection_timeout (time_t sec, time_t usec = 0 );
3815+ void set_interface (const std::string &intf);
37883816
37893817#ifdef CPPHTTPLIB_SSL_ENABLED
37903818 void set_ca_cert_path (const std::string &path);
@@ -3810,6 +3838,13 @@ class WebSocketClient {
38103838 time_t write_timeout_usec_ = CPPHTTPLIB_CLIENT_WRITE_TIMEOUT_USECOND;
38113839 time_t websocket_ping_interval_sec_ =
38123840 CPPHTTPLIB_WEBSOCKET_PING_INTERVAL_SECOND;
3841+ int address_family_ = AF_UNSPEC;
3842+ bool tcp_nodelay_ = CPPHTTPLIB_TCP_NODELAY;
3843+ bool ipv6_v6only_ = CPPHTTPLIB_IPV6_V6ONLY;
3844+ SocketOptions socket_options_ = nullptr ;
3845+ time_t connection_timeout_sec_ = CPPHTTPLIB_CONNECTION_TIMEOUT_SECOND;
3846+ time_t connection_timeout_usec_ = CPPHTTPLIB_CONNECTION_TIMEOUT_USECOND;
3847+ std::string interface_;
38133848
38143849#ifdef CPPHTTPLIB_SSL_ENABLED
38153850 bool is_ssl_ = false ;
0 commit comments