@@ -702,9 +702,16 @@ class ClientImpl {
702
702
std::shared_ptr<Response> Get (const char *path, const Headers &headers,
703
703
ContentReceiver content_receiver,
704
704
Progress progress);
705
+ std::shared_ptr<Response> Get (const char *path,
706
+ ResponseHandler response_handler,
707
+ ContentReceiver content_receiver);
705
708
std::shared_ptr<Response> Get (const char *path, const Headers &headers,
706
709
ResponseHandler response_handler,
707
710
ContentReceiver content_receiver);
711
+ std::shared_ptr<Response> Get (const char *path,
712
+ ResponseHandler response_handler,
713
+ ContentReceiver content_receiver,
714
+ Progress progress);
708
715
std::shared_ptr<Response> Get (const char *path, const Headers &headers,
709
716
ResponseHandler response_handler,
710
717
ContentReceiver content_receiver,
@@ -781,6 +788,8 @@ class ClientImpl {
781
788
782
789
void stop ();
783
790
791
+ void set_default_headers (Headers headers);
792
+
784
793
void set_tcp_nodelay (bool on);
785
794
void set_socket_options (SocketOptions socket_options);
786
795
@@ -838,6 +847,9 @@ class ClientImpl {
838
847
mutable std::mutex socket_mutex_;
839
848
std::recursive_mutex request_mutex_;
840
849
850
+ // Default headers
851
+ Headers default_headers_;
852
+
841
853
// Settings
842
854
std::string client_cert_path_;
843
855
std::string client_key_path_;
@@ -967,13 +979,20 @@ class Client {
967
979
std::shared_ptr<Response> Get (const char *path, const Headers &headers,
968
980
ContentReceiver content_receiver,
969
981
Progress progress);
982
+ std::shared_ptr<Response> Get (const char *path,
983
+ ResponseHandler response_handler,
984
+ ContentReceiver content_receiver);
970
985
std::shared_ptr<Response> Get (const char *path, const Headers &headers,
971
986
ResponseHandler response_handler,
972
987
ContentReceiver content_receiver);
973
988
std::shared_ptr<Response> Get (const char *path, const Headers &headers,
974
989
ResponseHandler response_handler,
975
990
ContentReceiver content_receiver,
976
991
Progress progress);
992
+ std::shared_ptr<Response> Get (const char *path,
993
+ ResponseHandler response_handler,
994
+ ContentReceiver content_receiver,
995
+ Progress progress);
977
996
978
997
std::shared_ptr<Response> Head (const char *path);
979
998
std::shared_ptr<Response> Head (const char *path, const Headers &headers);
@@ -1044,6 +1063,8 @@ class Client {
1044
1063
1045
1064
void stop ();
1046
1065
1066
+ void set_default_headers (Headers headers);
1067
+
1047
1068
void set_tcp_nodelay (bool on);
1048
1069
void set_socket_options (SocketOptions socket_options);
1049
1070
@@ -3285,7 +3306,7 @@ make_basic_authentication_header(const std::string &username,
3285
3306
3286
3307
inline std::pair<std::string, std::string>
3287
3308
make_bearer_token_authentication_header (const std::string &token,
3288
- bool is_proxy = false ) {
3309
+ bool is_proxy = false ) {
3289
3310
auto field = " Bearer " + token;
3290
3311
auto key = is_proxy ? " Proxy-Authorization" : " Authorization" ;
3291
3312
return std::make_pair (key, field);
@@ -4788,7 +4809,8 @@ inline std::shared_ptr<Response> ClientImpl::send_with_content_provider(
4788
4809
ContentProvider content_provider, const char *content_type) {
4789
4810
Request req;
4790
4811
req.method = method;
4791
- req.headers = headers;
4812
+ req.headers = default_headers_;
4813
+ req.headers .insert (headers.begin (), headers.end ());
4792
4814
req.path = path;
4793
4815
4794
4816
if (content_type) { req.headers .emplace (" Content-Type" , content_type); }
@@ -4928,7 +4950,8 @@ ClientImpl::Get(const char *path, const Headers &headers, Progress progress) {
4928
4950
Request req;
4929
4951
req.method = " GET" ;
4930
4952
req.path = path;
4931
- req.headers = headers;
4953
+ req.headers = default_headers_;
4954
+ req.headers .insert (headers.begin (), headers.end ());
4932
4955
req.progress = std::move (progress);
4933
4956
4934
4957
auto res = std::make_shared<Response>();
@@ -4960,6 +4983,13 @@ ClientImpl::Get(const char *path, const Headers &headers,
4960
4983
std::move (progress));
4961
4984
}
4962
4985
4986
+ inline std::shared_ptr<Response>
4987
+ ClientImpl::Get (const char *path, ResponseHandler response_handler,
4988
+ ContentReceiver content_receiver) {
4989
+ return Get (path, Headers (), std::move (response_handler), content_receiver,
4990
+ Progress ());
4991
+ }
4992
+
4963
4993
inline std::shared_ptr<Response>
4964
4994
ClientImpl::Get (const char *path, const Headers &headers,
4965
4995
ResponseHandler response_handler,
@@ -4968,14 +4998,22 @@ ClientImpl::Get(const char *path, const Headers &headers,
4968
4998
Progress ());
4969
4999
}
4970
5000
5001
+ inline std::shared_ptr<Response>
5002
+ ClientImpl::Get (const char *path, ResponseHandler response_handler,
5003
+ ContentReceiver content_receiver, Progress progress) {
5004
+ return Get (path, Headers (), std::move (response_handler), content_receiver,
5005
+ progress);
5006
+ }
5007
+
4971
5008
inline std::shared_ptr<Response>
4972
5009
ClientImpl::Get (const char *path, const Headers &headers,
4973
5010
ResponseHandler response_handler,
4974
5011
ContentReceiver content_receiver, Progress progress) {
4975
5012
Request req;
4976
5013
req.method = " GET" ;
4977
5014
req.path = path;
4978
- req.headers = headers;
5015
+ req.headers = default_headers_;
5016
+ req.headers .insert (headers.begin (), headers.end ());
4979
5017
req.response_handler = std::move (response_handler);
4980
5018
req.content_receiver = std::move (content_receiver);
4981
5019
req.progress = std::move (progress);
@@ -4992,7 +5030,8 @@ inline std::shared_ptr<Response> ClientImpl::Head(const char *path,
4992
5030
const Headers &headers) {
4993
5031
Request req;
4994
5032
req.method = " HEAD" ;
4995
- req.headers = headers;
5033
+ req.headers = default_headers_;
5034
+ req.headers .insert (headers.begin (), headers.end ());
4996
5035
req.path = path;
4997
5036
4998
5037
auto res = std::make_shared<Response>();
@@ -5171,7 +5210,8 @@ inline std::shared_ptr<Response> ClientImpl::Delete(const char *path,
5171
5210
const char *content_type) {
5172
5211
Request req;
5173
5212
req.method = " DELETE" ;
5174
- req.headers = headers;
5213
+ req.headers = default_headers_;
5214
+ req.headers .insert (headers.begin (), headers.end ());
5175
5215
req.path = path;
5176
5216
5177
5217
if (content_type) { req.headers .emplace (" Content-Type" , content_type); }
@@ -5190,8 +5230,9 @@ inline std::shared_ptr<Response> ClientImpl::Options(const char *path,
5190
5230
const Headers &headers) {
5191
5231
Request req;
5192
5232
req.method = " OPTIONS" ;
5233
+ req.headers = default_headers_;
5234
+ req.headers .insert (headers.begin (), headers.end ());
5193
5235
req.path = path;
5194
- req.headers = headers;
5195
5236
5196
5237
auto res = std::make_shared<Response>();
5197
5238
@@ -5250,6 +5291,10 @@ inline void ClientImpl::set_keep_alive(bool on) { keep_alive_ = on; }
5250
5291
5251
5292
inline void ClientImpl::set_follow_location (bool on) { follow_location_ = on; }
5252
5293
5294
+ inline void ClientImpl::set_default_headers (Headers headers) {
5295
+ default_headers_ = std::move (headers);
5296
+ }
5297
+
5253
5298
inline void ClientImpl::set_tcp_nodelay (bool on) { tcp_nodelay_ = on; }
5254
5299
5255
5300
inline void ClientImpl::set_socket_options (SocketOptions socket_options) {
@@ -6001,12 +6046,24 @@ inline std::shared_ptr<Response> Client::Get(const char *path,
6001
6046
Progress progress) {
6002
6047
return cli_->Get (path, headers, content_receiver, progress);
6003
6048
}
6049
+ inline std::shared_ptr<Response> Client::Get (const char *path,
6050
+ ResponseHandler response_handler,
6051
+ ContentReceiver content_receiver) {
6052
+ return cli_->Get (path, Headers (), response_handler, content_receiver);
6053
+ }
6004
6054
inline std::shared_ptr<Response> Client::Get (const char *path,
6005
6055
const Headers &headers,
6006
6056
ResponseHandler response_handler,
6007
6057
ContentReceiver content_receiver) {
6008
6058
return cli_->Get (path, headers, response_handler, content_receiver);
6009
6059
}
6060
+ inline std::shared_ptr<Response> Client::Get (const char *path,
6061
+ ResponseHandler response_handler,
6062
+ ContentReceiver content_receiver,
6063
+ Progress progress) {
6064
+ return cli_->Get (path, Headers (), response_handler, content_receiver,
6065
+ progress);
6066
+ }
6010
6067
inline std::shared_ptr<Response> Client::Get (const char *path,
6011
6068
const Headers &headers,
6012
6069
ResponseHandler response_handler,
@@ -6157,6 +6214,10 @@ inline size_t Client::is_socket_open() const { return cli_->is_socket_open(); }
6157
6214
6158
6215
inline void Client::stop () { cli_->stop (); }
6159
6216
6217
+ inline void Client::set_default_headers (Headers headers) {
6218
+ cli_->set_default_headers (std::move (headers));
6219
+ }
6220
+
6160
6221
inline void Client::set_tcp_nodelay (bool on) { cli_->set_tcp_nodelay (on); }
6161
6222
inline void Client::set_socket_options (SocketOptions socket_options) {
6162
6223
cli_->set_socket_options (socket_options);
0 commit comments