@@ -700,7 +700,9 @@ class Client {
700
700
701
701
void set_basic_auth (const char *username, const char *password);
702
702
703
+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
703
704
void set_digest_auth (const char *username, const char *password);
705
+ #endif
704
706
705
707
void set_follow_location (bool on);
706
708
@@ -712,7 +714,9 @@ class Client {
712
714
713
715
void set_proxy_basic_auth (const char *username, const char *password);
714
716
717
+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
715
718
void set_proxy_digest_auth (const char *username, const char *password);
719
+ #endif
716
720
717
721
void set_logger (Logger logger);
718
722
@@ -736,8 +740,10 @@ class Client {
736
740
737
741
std::string basic_auth_username_;
738
742
std::string basic_auth_password_;
743
+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
739
744
std::string digest_auth_username_;
740
745
std::string digest_auth_password_;
746
+ #endif
741
747
742
748
bool follow_location_ = false ;
743
749
@@ -750,8 +756,10 @@ class Client {
750
756
751
757
std::string proxy_basic_auth_username_;
752
758
std::string proxy_basic_auth_password_;
759
+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
753
760
std::string proxy_digest_auth_username_;
754
761
std::string proxy_digest_auth_password_;
762
+ #endif
755
763
756
764
Logger logger_;
757
765
@@ -764,17 +772,21 @@ class Client {
764
772
keep_alive_max_count_ = rhs.keep_alive_max_count_ ;
765
773
basic_auth_username_ = rhs.basic_auth_username_ ;
766
774
basic_auth_password_ = rhs.basic_auth_password_ ;
775
+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
767
776
digest_auth_username_ = rhs.digest_auth_username_ ;
768
777
digest_auth_password_ = rhs.digest_auth_password_ ;
778
+ #endif
769
779
follow_location_ = rhs.follow_location_ ;
770
780
compress_ = rhs.compress_ ;
771
781
interface_ = rhs.interface_ ;
772
782
proxy_host_ = rhs.proxy_host_ ;
773
783
proxy_port_ = rhs.proxy_port_ ;
774
784
proxy_basic_auth_username_ = rhs.proxy_basic_auth_username_ ;
775
785
proxy_basic_auth_password_ = rhs.proxy_basic_auth_password_ ;
786
+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
776
787
proxy_digest_auth_username_ = rhs.proxy_digest_auth_username_ ;
777
788
proxy_digest_auth_password_ = rhs.proxy_digest_auth_password_ ;
789
+ #endif
778
790
logger_ = rhs.logger_ ;
779
791
}
780
792
@@ -783,9 +795,11 @@ class Client {
783
795
bool read_response_line (Stream &strm, Response &res);
784
796
bool write_request (Stream &strm, const Request &req, bool last_connection);
785
797
bool redirect (const Request &req, Response &res);
786
- bool connect (socket_t sock, Response &res, bool &error);
787
798
bool handle_request (Stream &strm, const Request &req, Response &res,
788
799
bool last_connection, bool &connection_close);
800
+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
801
+ bool connect (socket_t sock, Response &res, bool &error);
802
+ #endif
789
803
790
804
std::shared_ptr<Response> send_with_content_provider (
791
805
const char *method, const char *path, const Headers &headers,
@@ -3498,6 +3512,57 @@ inline bool Client::send(const std::vector<Request> &requests,
3498
3512
return true ;
3499
3513
}
3500
3514
3515
+ inline bool Client::handle_request (Stream &strm, const Request &req,
3516
+ Response &res, bool last_connection,
3517
+ bool &connection_close) {
3518
+ if (req.path .empty ()) { return false ; }
3519
+
3520
+ bool ret;
3521
+
3522
+ if (!is_ssl () && !proxy_host_.empty ()) {
3523
+ auto req2 = req;
3524
+ req2.path = " http://" + host_and_port_ + req.path ;
3525
+ ret = process_request (strm, req2, res, last_connection, connection_close);
3526
+ } else {
3527
+ ret = process_request (strm, req, res, last_connection, connection_close);
3528
+ }
3529
+
3530
+ if (!ret) { return false ; }
3531
+
3532
+ if (300 < res.status && res.status < 400 && follow_location_) {
3533
+ ret = redirect (req, res);
3534
+ }
3535
+
3536
+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
3537
+ if (res.status == 401 || res.status == 407 ) {
3538
+ auto is_proxy = res.status == 407 ;
3539
+ const auto &username =
3540
+ is_proxy ? proxy_digest_auth_username_ : digest_auth_username_;
3541
+ const auto &password =
3542
+ is_proxy ? proxy_digest_auth_password_ : digest_auth_password_;
3543
+
3544
+ if (!username.empty () && !password.empty ()) {
3545
+ std::map<std::string, std::string> auth;
3546
+ if (parse_www_authenticate (res, auth, is_proxy)) {
3547
+ Request new_req = req;
3548
+ auto key = is_proxy ? " Proxy-Authorization" : " WWW-Authorization" ;
3549
+ new_req.headers .erase (key);
3550
+ new_req.headers .insert (make_digest_authentication_header (
3551
+ req, auth, 1 , random_string (10 ), username, password, is_proxy));
3552
+
3553
+ Response new_res;
3554
+
3555
+ ret = send (new_req, new_res);
3556
+ if (ret) { res = new_res; }
3557
+ }
3558
+ }
3559
+ }
3560
+ #endif
3561
+
3562
+ return ret;
3563
+ }
3564
+
3565
+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
3501
3566
inline bool Client::connect (socket_t sock, Response &res, bool &error) {
3502
3567
error = true ;
3503
3568
Response res2;
@@ -3548,57 +3613,8 @@ inline bool Client::connect(socket_t sock, Response &res, bool &error) {
3548
3613
3549
3614
return true ;
3550
3615
}
3551
-
3552
- inline bool Client::handle_request (Stream &strm, const Request &req,
3553
- Response &res, bool last_connection,
3554
- bool &connection_close) {
3555
- if (req.path .empty ()) { return false ; }
3556
-
3557
- bool ret;
3558
-
3559
- if (!is_ssl () && !proxy_host_.empty ()) {
3560
- auto req2 = req;
3561
- req2.path = " http://" + host_and_port_ + req.path ;
3562
- ret = process_request (strm, req2, res, last_connection, connection_close);
3563
- } else {
3564
- ret = process_request (strm, req, res, last_connection, connection_close);
3565
- }
3566
-
3567
- if (!ret) { return false ; }
3568
-
3569
- if (300 < res.status && res.status < 400 && follow_location_) {
3570
- ret = redirect (req, res);
3571
- }
3572
-
3573
- #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
3574
- if (res.status == 401 || res.status == 407 ) {
3575
- auto is_proxy = res.status == 407 ;
3576
- const auto &username =
3577
- is_proxy ? proxy_digest_auth_username_ : digest_auth_username_;
3578
- const auto &password =
3579
- is_proxy ? proxy_digest_auth_password_ : digest_auth_password_;
3580
-
3581
- if (!username.empty () && !password.empty ()) {
3582
- std::map<std::string, std::string> auth;
3583
- if (parse_www_authenticate (res, auth, is_proxy)) {
3584
- Request new_req = req;
3585
- auto key = is_proxy ? " Proxy-Authorization" : " WWW-Authorization" ;
3586
- new_req.headers .erase (key);
3587
- new_req.headers .insert (make_digest_authentication_header (
3588
- req, auth, 1 , random_string (10 ), username, password, is_proxy));
3589
-
3590
- Response new_res;
3591
-
3592
- ret = send (new_req, new_res);
3593
- if (ret) { res = new_res; }
3594
- }
3595
- }
3596
- }
3597
3616
#endif
3598
3617
3599
- return ret;
3600
- }
3601
-
3602
3618
inline bool Client::redirect (const Request &req, Response &res) {
3603
3619
if (req.redirect_count == 0 ) { return false ; }
3604
3620
@@ -4131,11 +4147,13 @@ inline void Client::set_basic_auth(const char *username, const char *password) {
4131
4147
basic_auth_password_ = password;
4132
4148
}
4133
4149
4150
+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
4134
4151
inline void Client::set_digest_auth (const char *username,
4135
4152
const char *password) {
4136
4153
digest_auth_username_ = username;
4137
4154
digest_auth_password_ = password;
4138
4155
}
4156
+ #endif
4139
4157
4140
4158
inline void Client::set_follow_location (bool on) { follow_location_ = on; }
4141
4159
@@ -4154,11 +4172,13 @@ inline void Client::set_proxy_basic_auth(const char *username,
4154
4172
proxy_basic_auth_password_ = password;
4155
4173
}
4156
4174
4175
+ #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
4157
4176
inline void Client::set_proxy_digest_auth (const char *username,
4158
4177
const char *password) {
4159
4178
proxy_digest_auth_username_ = username;
4160
4179
proxy_digest_auth_password_ = password;
4161
4180
}
4181
+ #endif
4162
4182
4163
4183
inline void Client::set_logger (Logger logger) { logger_ = std::move (logger); }
4164
4184
0 commit comments