@@ -657,78 +657,63 @@ class Client {
657
657
std::shared_ptr<Response> Head (const char *path, const Headers &headers);
658
658
659
659
std::shared_ptr<Response> Post (const char *path, const std::string &body,
660
- const char *content_type,
661
- bool compress = false );
660
+ const char *content_type);
662
661
663
662
std::shared_ptr<Response> Post (const char *path, const Headers &headers,
664
663
const std::string &body,
665
- const char *content_type,
666
- bool compress = false );
664
+ const char *content_type);
667
665
668
666
std::shared_ptr<Response> Post (const char *path, size_t content_length,
669
667
ContentProvider content_provider,
670
- const char *content_type,
671
- bool compress = false );
668
+ const char *content_type);
672
669
673
670
std::shared_ptr<Response> Post (const char *path, const Headers &headers,
674
671
size_t content_length,
675
672
ContentProvider content_provider,
676
- const char *content_type,
677
- bool compress = false );
673
+ const char *content_type);
678
674
679
- std::shared_ptr<Response> Post (const char *path, const Params ¶ms,
680
- bool compress = false );
675
+ std::shared_ptr<Response> Post (const char *path, const Params ¶ms);
681
676
682
677
std::shared_ptr<Response> Post (const char *path, const Headers &headers,
683
- const Params ¶ms, bool compress = false );
678
+ const Params ¶ms);
684
679
685
680
std::shared_ptr<Response> Post (const char *path,
686
- const MultipartFormDataItems &items,
687
- bool compress = false );
681
+ const MultipartFormDataItems &items);
688
682
689
683
std::shared_ptr<Response> Post (const char *path, const Headers &headers,
690
- const MultipartFormDataItems &items,
691
- bool compress = false );
684
+ const MultipartFormDataItems &items);
692
685
693
686
std::shared_ptr<Response> Put (const char *path, const std::string &body,
694
- const char *content_type,
695
- bool compress = false );
687
+ const char *content_type);
696
688
697
689
std::shared_ptr<Response> Put (const char *path, const Headers &headers,
698
690
const std::string &body,
699
- const char *content_type,
700
- bool compress = false );
691
+ const char *content_type);
701
692
702
693
std::shared_ptr<Response> Put (const char *path, size_t content_length,
703
694
ContentProvider content_provider,
704
- const char *content_type,
705
- bool compress = false );
695
+ const char *content_type);
706
696
707
697
std::shared_ptr<Response> Put (const char *path, const Headers &headers,
708
698
size_t content_length,
709
699
ContentProvider content_provider,
710
- const char *content_type,
711
- bool compress = false );
700
+ const char *content_type);
712
701
713
702
std::shared_ptr<Response> Patch (const char *path, const std::string &body,
714
- const char *content_type,
715
- bool compress = false );
703
+ const char *content_type);
716
704
717
705
std::shared_ptr<Response> Patch (const char *path, const Headers &headers,
718
706
const std::string &body,
719
- const char *content_type,
720
- bool compress = false );
707
+ const char *content_type);
721
708
722
709
std::shared_ptr<Response> Patch (const char *path, size_t content_length,
723
710
ContentProvider content_provider,
724
- const char *content_type,
725
- bool compress = false );
711
+ const char *content_type);
726
712
727
713
std::shared_ptr<Response> Patch (const char *path, const Headers &headers,
728
714
size_t content_length,
729
715
ContentProvider content_provider,
730
- const char *content_type,
731
- bool compress = false );
716
+ const char *content_type);
732
717
733
718
std::shared_ptr<Response> Delete (const char *path);
734
719
@@ -754,9 +739,11 @@ class Client {
754
739
755
740
void set_read_timeout (time_t sec, time_t usec);
756
741
742
+ void set_auth (const char *username, const char *password);
743
+
757
744
void follow_location (bool on);
758
745
759
- void set_auth ( const char *username, const char *password );
746
+ void compress ( bool on );
760
747
761
748
protected:
762
749
bool process_request (Stream &strm, const Request &req, Response &res,
@@ -769,9 +756,10 @@ class Client {
769
756
size_t keep_alive_max_count_;
770
757
time_t read_timeout_sec_;
771
758
time_t read_timeout_usec_;
772
- size_t follow_location_;
759
+ bool follow_location_;
773
760
std::string username_;
774
761
std::string password_;
762
+ bool compress_;
775
763
776
764
private:
777
765
socket_t create_client_socket () const ;
@@ -784,7 +772,7 @@ class Client {
784
772
const Headers &headers, const std::string &body,
785
773
size_t content_length,
786
774
ContentProvider content_provider,
787
- const char *content_type, bool compress );
775
+ const char *content_type);
788
776
789
777
virtual bool process_and_close_socket (
790
778
socket_t sock, size_t request_count,
@@ -3331,7 +3319,8 @@ inline Client::Client(const char *host, int port, time_t timeout_sec)
3331
3319
keep_alive_max_count_(CPPHTTPLIB_KEEPALIVE_MAX_COUNT),
3332
3320
read_timeout_sec_(CPPHTTPLIB_READ_TIMEOUT_SECOND),
3333
3321
read_timeout_usec_(CPPHTTPLIB_READ_TIMEOUT_USECOND),
3334
- follow_location_(false ) {}
3322
+ follow_location_(false ),
3323
+ compress_(false ) {}
3335
3324
3336
3325
inline Client::~Client () {}
3337
3326
@@ -3570,11 +3559,7 @@ inline void Client::write_request(Stream &strm, const Request &req,
3570
3559
inline std::shared_ptr<Response> Client::send_with_content_provider (
3571
3560
const char *method, const char *path, const Headers &headers,
3572
3561
const std::string &body, size_t content_length,
3573
- ContentProvider content_provider, const char *content_type, bool compress) {
3574
- #ifndef CPPHTTPLIB_ZLIB_SUPPORT
3575
- (void )compress;
3576
- #endif
3577
-
3562
+ ContentProvider content_provider, const char *content_type) {
3578
3563
Request req;
3579
3564
req.method = method;
3580
3565
req.headers = headers;
@@ -3583,7 +3568,7 @@ inline std::shared_ptr<Response> Client::send_with_content_provider(
3583
3568
req.headers .emplace (" Content-Type" , content_type);
3584
3569
3585
3570
#ifdef CPPHTTPLIB_ZLIB_SUPPORT
3586
- if (compress ) {
3571
+ if (compress_ ) {
3587
3572
if (content_provider) {
3588
3573
size_t offset = 0 ;
3589
3574
while (offset < content_length) {
@@ -3771,45 +3756,40 @@ inline std::shared_ptr<Response> Client::Head(const char *path,
3771
3756
3772
3757
inline std::shared_ptr<Response> Client::Post (const char *path,
3773
3758
const std::string &body,
3774
- const char *content_type,
3775
- bool compress) {
3776
- return Post (path, Headers (), body, content_type, compress);
3759
+ const char *content_type) {
3760
+ return Post (path, Headers (), body, content_type);
3777
3761
}
3778
3762
3779
3763
inline std::shared_ptr<Response>
3780
3764
Client::Post (const char *path, const Headers &headers, const std::string &body,
3781
- const char *content_type, bool compress ) {
3765
+ const char *content_type) {
3782
3766
return send_with_content_provider (" POST" , path, headers, body, 0 , nullptr ,
3783
- content_type, compress );
3767
+ content_type);
3784
3768
}
3785
3769
3786
3770
inline std::shared_ptr<Response>
3787
- Client::Post (const char *path, const Params ¶ms, bool compress ) {
3788
- return Post (path, Headers (), params, compress );
3771
+ Client::Post (const char *path, const Params ¶ms) {
3772
+ return Post (path, Headers (), params);
3789
3773
}
3790
3774
3791
3775
inline std::shared_ptr<Response> Client::Post (const char *path,
3792
3776
size_t content_length,
3793
3777
ContentProvider content_provider,
3794
- const char *content_type,
3795
- bool compress) {
3796
- return Post (path, Headers (), content_length, content_provider, content_type,
3797
- compress);
3778
+ const char *content_type) {
3779
+ return Post (path, Headers (), content_length, content_provider, content_type);
3798
3780
}
3799
3781
3800
3782
inline std::shared_ptr<Response>
3801
3783
Client::Post (const char *path, const Headers &headers, size_t content_length,
3802
- ContentProvider content_provider, const char *content_type,
3803
- bool compress) {
3784
+ ContentProvider content_provider, const char *content_type) {
3804
3785
return send_with_content_provider (" POST" , path, headers, std::string (),
3805
3786
content_length, content_provider,
3806
- content_type, compress );
3787
+ content_type);
3807
3788
}
3808
3789
3809
3790
inline std::shared_ptr<Response> Client::Post (const char *path,
3810
3791
const Headers &headers,
3811
- const Params ¶ms,
3812
- bool compress) {
3792
+ const Params ¶ms) {
3813
3793
std::string query;
3814
3794
for (auto it = params.begin (); it != params.end (); ++it) {
3815
3795
if (it != params.begin ()) { query += " &" ; }
@@ -3818,19 +3798,17 @@ inline std::shared_ptr<Response> Client::Post(const char *path,
3818
3798
query += detail::encode_url (it->second );
3819
3799
}
3820
3800
3821
- return Post (path, headers, query, " application/x-www-form-urlencoded" ,
3822
- compress);
3801
+ return Post (path, headers, query, " application/x-www-form-urlencoded" );
3823
3802
}
3824
3803
3825
3804
inline std::shared_ptr<Response>
3826
- Client::Post (const char *path, const MultipartFormDataItems &items,
3827
- bool compress) {
3828
- return Post (path, Headers (), items, compress);
3805
+ Client::Post (const char *path, const MultipartFormDataItems &items) {
3806
+ return Post (path, Headers (), items);
3829
3807
}
3830
3808
3831
3809
inline std::shared_ptr<Response>
3832
3810
Client::Post (const char *path, const Headers &headers,
3833
- const MultipartFormDataItems &items, bool compress ) {
3811
+ const MultipartFormDataItems &items) {
3834
3812
auto boundary = detail::make_multipart_data_boundary ();
3835
3813
3836
3814
std::string body;
@@ -3852,71 +3830,63 @@ Client::Post(const char *path, const Headers &headers,
3852
3830
body += " --" + boundary + " --\r\n " ;
3853
3831
3854
3832
std::string content_type = " multipart/form-data; boundary=" + boundary;
3855
- return Post (path, headers, body, content_type.c_str (), compress );
3833
+ return Post (path, headers, body, content_type.c_str ());
3856
3834
}
3857
3835
3858
3836
inline std::shared_ptr<Response> Client::Put (const char *path,
3859
3837
const std::string &body,
3860
- const char *content_type,
3861
- bool compress) {
3862
- return Put (path, Headers (), body, content_type, compress);
3838
+ const char *content_type) {
3839
+ return Put (path, Headers (), body, content_type);
3863
3840
}
3864
3841
3865
3842
inline std::shared_ptr<Response>
3866
3843
Client::Put (const char *path, const Headers &headers, const std::string &body,
3867
- const char *content_type, bool compress ) {
3844
+ const char *content_type) {
3868
3845
return send_with_content_provider (" PUT" , path, headers, body, 0 , nullptr ,
3869
- content_type, compress );
3846
+ content_type);
3870
3847
}
3871
3848
3872
3849
inline std::shared_ptr<Response> Client::Put (const char *path,
3873
3850
size_t content_length,
3874
3851
ContentProvider content_provider,
3875
- const char *content_type,
3876
- bool compress) {
3877
- return Put (path, Headers (), content_length, content_provider, content_type,
3878
- compress);
3852
+ const char *content_type) {
3853
+ return Put (path, Headers (), content_length, content_provider, content_type);
3879
3854
}
3880
3855
3881
3856
inline std::shared_ptr<Response>
3882
3857
Client::Put (const char *path, const Headers &headers, size_t content_length,
3883
- ContentProvider content_provider, const char *content_type,
3884
- bool compress) {
3858
+ ContentProvider content_provider, const char *content_type) {
3885
3859
return send_with_content_provider (" PUT" , path, headers, std::string (),
3886
3860
content_length, content_provider,
3887
- content_type, compress );
3861
+ content_type);
3888
3862
}
3889
3863
3890
3864
inline std::shared_ptr<Response> Client::Patch (const char *path,
3891
3865
const std::string &body,
3892
- const char *content_type,
3893
- bool compress) {
3894
- return Patch (path, Headers (), body, content_type, compress);
3866
+ const char *content_type) {
3867
+ return Patch (path, Headers (), body, content_type);
3895
3868
}
3896
3869
3897
3870
inline std::shared_ptr<Response>
3898
3871
Client::Patch (const char *path, const Headers &headers, const std::string &body,
3899
- const char *content_type, bool compress ) {
3872
+ const char *content_type) {
3900
3873
return send_with_content_provider (" PATCH" , path, headers, body, 0 , nullptr ,
3901
- content_type, compress );
3874
+ content_type);
3902
3875
}
3903
3876
3904
3877
inline std::shared_ptr<Response> Client::Patch (const char *path,
3905
3878
size_t content_length,
3906
3879
ContentProvider content_provider,
3907
- const char *content_type,
3908
- bool compress) {
3909
- return Patch (path, Headers (), content_length, content_provider, content_type,
3910
- compress);
3880
+ const char *content_type) {
3881
+ return Patch (path, Headers (), content_length, content_provider, content_type);
3911
3882
}
3912
3883
3913
3884
inline std::shared_ptr<Response>
3914
3885
Client::Patch (const char *path, const Headers &headers, size_t content_length,
3915
- ContentProvider content_provider, const char *content_type,
3916
- bool compress) {
3886
+ ContentProvider content_provider, const char *content_type) {
3917
3887
return send_with_content_provider (" PATCH" , path, headers, std::string (),
3918
3888
content_length, content_provider,
3919
- content_type, compress );
3889
+ content_type);
3920
3890
}
3921
3891
3922
3892
inline std::shared_ptr<Response> Client::Delete (const char *path) {
@@ -3976,13 +3946,15 @@ inline void Client::set_read_timeout(time_t sec, time_t usec) {
3976
3946
read_timeout_usec_ = usec;
3977
3947
}
3978
3948
3979
- inline void Client::follow_location (bool on) { follow_location_ = on; }
3980
-
3981
3949
inline void Client::set_auth (const char *username, const char *password) {
3982
3950
username_ = username;
3983
3951
password_ = password;
3984
3952
}
3985
3953
3954
+ inline void Client::follow_location (bool on) { follow_location_ = on; }
3955
+
3956
+ inline void Client::compress (bool on) { compress_ = on; }
3957
+
3986
3958
/*
3987
3959
* SSL Implementation
3988
3960
*/
0 commit comments