@@ -702,9 +702,16 @@ class ClientImpl {
702702 std::shared_ptr<Response> Get (const char *path, const Headers &headers,
703703 ContentReceiver content_receiver,
704704 Progress progress);
705+ std::shared_ptr<Response> Get (const char *path,
706+ ResponseHandler response_handler,
707+ ContentReceiver content_receiver);
705708 std::shared_ptr<Response> Get (const char *path, const Headers &headers,
706709 ResponseHandler response_handler,
707710 ContentReceiver content_receiver);
711+ std::shared_ptr<Response> Get (const char *path,
712+ ResponseHandler response_handler,
713+ ContentReceiver content_receiver,
714+ Progress progress);
708715 std::shared_ptr<Response> Get (const char *path, const Headers &headers,
709716 ResponseHandler response_handler,
710717 ContentReceiver content_receiver,
@@ -781,6 +788,8 @@ class ClientImpl {
781788
782789 void stop ();
783790
791+ void set_default_headers (Headers headers);
792+
784793 void set_tcp_nodelay (bool on);
785794 void set_socket_options (SocketOptions socket_options);
786795
@@ -838,6 +847,9 @@ class ClientImpl {
838847 mutable std::mutex socket_mutex_;
839848 std::recursive_mutex request_mutex_;
840849
850+ // Default headers
851+ Headers default_headers_;
852+
841853 // Settings
842854 std::string client_cert_path_;
843855 std::string client_key_path_;
@@ -967,13 +979,20 @@ class Client {
967979 std::shared_ptr<Response> Get (const char *path, const Headers &headers,
968980 ContentReceiver content_receiver,
969981 Progress progress);
982+ std::shared_ptr<Response> Get (const char *path,
983+ ResponseHandler response_handler,
984+ ContentReceiver content_receiver);
970985 std::shared_ptr<Response> Get (const char *path, const Headers &headers,
971986 ResponseHandler response_handler,
972987 ContentReceiver content_receiver);
973988 std::shared_ptr<Response> Get (const char *path, const Headers &headers,
974989 ResponseHandler response_handler,
975990 ContentReceiver content_receiver,
976991 Progress progress);
992+ std::shared_ptr<Response> Get (const char *path,
993+ ResponseHandler response_handler,
994+ ContentReceiver content_receiver,
995+ Progress progress);
977996
978997 std::shared_ptr<Response> Head (const char *path);
979998 std::shared_ptr<Response> Head (const char *path, const Headers &headers);
@@ -1044,6 +1063,8 @@ class Client {
10441063
10451064 void stop ();
10461065
1066+ void set_default_headers (Headers headers);
1067+
10471068 void set_tcp_nodelay (bool on);
10481069 void set_socket_options (SocketOptions socket_options);
10491070
@@ -3285,7 +3306,7 @@ make_basic_authentication_header(const std::string &username,
32853306
32863307inline std::pair<std::string, std::string>
32873308make_bearer_token_authentication_header (const std::string &token,
3288- bool is_proxy = false ) {
3309+ bool is_proxy = false ) {
32893310 auto field = " Bearer " + token;
32903311 auto key = is_proxy ? " Proxy-Authorization" : " Authorization" ;
32913312 return std::make_pair (key, field);
@@ -4788,7 +4809,8 @@ inline std::shared_ptr<Response> ClientImpl::send_with_content_provider(
47884809 ContentProvider content_provider, const char *content_type) {
47894810 Request req;
47904811 req.method = method;
4791- req.headers = headers;
4812+ req.headers = default_headers_;
4813+ req.headers .insert (headers.begin (), headers.end ());
47924814 req.path = path;
47934815
47944816 if (content_type) { req.headers .emplace (" Content-Type" , content_type); }
@@ -4928,7 +4950,8 @@ ClientImpl::Get(const char *path, const Headers &headers, Progress progress) {
49284950 Request req;
49294951 req.method = " GET" ;
49304952 req.path = path;
4931- req.headers = headers;
4953+ req.headers = default_headers_;
4954+ req.headers .insert (headers.begin (), headers.end ());
49324955 req.progress = std::move (progress);
49334956
49344957 auto res = std::make_shared<Response>();
@@ -4960,6 +4983,13 @@ ClientImpl::Get(const char *path, const Headers &headers,
49604983 std::move (progress));
49614984}
49624985
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+
49634993inline std::shared_ptr<Response>
49644994ClientImpl::Get (const char *path, const Headers &headers,
49654995 ResponseHandler response_handler,
@@ -4968,14 +4998,22 @@ ClientImpl::Get(const char *path, const Headers &headers,
49684998 Progress ());
49694999}
49705000
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+
49715008inline std::shared_ptr<Response>
49725009ClientImpl::Get (const char *path, const Headers &headers,
49735010 ResponseHandler response_handler,
49745011 ContentReceiver content_receiver, Progress progress) {
49755012 Request req;
49765013 req.method = " GET" ;
49775014 req.path = path;
4978- req.headers = headers;
5015+ req.headers = default_headers_;
5016+ req.headers .insert (headers.begin (), headers.end ());
49795017 req.response_handler = std::move (response_handler);
49805018 req.content_receiver = std::move (content_receiver);
49815019 req.progress = std::move (progress);
@@ -4992,7 +5030,8 @@ inline std::shared_ptr<Response> ClientImpl::Head(const char *path,
49925030 const Headers &headers) {
49935031 Request req;
49945032 req.method = " HEAD" ;
4995- req.headers = headers;
5033+ req.headers = default_headers_;
5034+ req.headers .insert (headers.begin (), headers.end ());
49965035 req.path = path;
49975036
49985037 auto res = std::make_shared<Response>();
@@ -5171,7 +5210,8 @@ inline std::shared_ptr<Response> ClientImpl::Delete(const char *path,
51715210 const char *content_type) {
51725211 Request req;
51735212 req.method = " DELETE" ;
5174- req.headers = headers;
5213+ req.headers = default_headers_;
5214+ req.headers .insert (headers.begin (), headers.end ());
51755215 req.path = path;
51765216
51775217 if (content_type) { req.headers .emplace (" Content-Type" , content_type); }
@@ -5190,8 +5230,9 @@ inline std::shared_ptr<Response> ClientImpl::Options(const char *path,
51905230 const Headers &headers) {
51915231 Request req;
51925232 req.method = " OPTIONS" ;
5233+ req.headers = default_headers_;
5234+ req.headers .insert (headers.begin (), headers.end ());
51935235 req.path = path;
5194- req.headers = headers;
51955236
51965237 auto res = std::make_shared<Response>();
51975238
@@ -5250,6 +5291,10 @@ inline void ClientImpl::set_keep_alive(bool on) { keep_alive_ = on; }
52505291
52515292inline void ClientImpl::set_follow_location (bool on) { follow_location_ = on; }
52525293
5294+ inline void ClientImpl::set_default_headers (Headers headers) {
5295+ default_headers_ = std::move (headers);
5296+ }
5297+
52535298inline void ClientImpl::set_tcp_nodelay (bool on) { tcp_nodelay_ = on; }
52545299
52555300inline void ClientImpl::set_socket_options (SocketOptions socket_options) {
@@ -6001,12 +6046,24 @@ inline std::shared_ptr<Response> Client::Get(const char *path,
60016046 Progress progress) {
60026047 return cli_->Get (path, headers, content_receiver, progress);
60036048}
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+ }
60046054inline std::shared_ptr<Response> Client::Get (const char *path,
60056055 const Headers &headers,
60066056 ResponseHandler response_handler,
60076057 ContentReceiver content_receiver) {
60086058 return cli_->Get (path, headers, response_handler, content_receiver);
60096059}
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+ }
60106067inline std::shared_ptr<Response> Client::Get (const char *path,
60116068 const Headers &headers,
60126069 ResponseHandler response_handler,
@@ -6157,6 +6214,10 @@ inline size_t Client::is_socket_open() const { return cli_->is_socket_open(); }
61576214
61586215inline void Client::stop () { cli_->stop (); }
61596216
6217+ inline void Client::set_default_headers (Headers headers) {
6218+ cli_->set_default_headers (std::move (headers));
6219+ }
6220+
61606221inline void Client::set_tcp_nodelay (bool on) { cli_->set_tcp_nodelay (on); }
61616222inline void Client::set_socket_options (SocketOptions socket_options) {
61626223 cli_->set_socket_options (socket_options);
0 commit comments