@@ -428,19 +428,6 @@ struct Response {
428428 ContentProvider content_provider_;
429429 std::function<void ()> content_provider_resource_releaser_;
430430 bool is_chunked_content_provider = false ;
431-
432- class ContentProviderAdapter {
433- public:
434- explicit ContentProviderAdapter (ContentProviderWithoutLength&& content_provider):
435- content_provider_(content_provider) {}
436-
437- bool operator ()(size_t offset, size_t , DataSink& sink) {
438- return content_provider_ (offset, sink);
439- }
440-
441- private:
442- ContentProviderWithoutLength content_provider_;
443- };
444431};
445432
446433class Stream {
@@ -3329,39 +3316,6 @@ class WSInit {
33293316static WSInit wsinit_;
33303317#endif
33313318
3332- } // namespace detail
3333-
3334- // Header utilities
3335- inline std::pair<std::string, std::string> make_range_header (Ranges ranges) {
3336- std::string field = " bytes=" ;
3337- auto i = 0 ;
3338- for (auto r : ranges) {
3339- if (i != 0 ) { field += " , " ; }
3340- if (r.first != -1 ) { field += std::to_string (r.first ); }
3341- field += ' -' ;
3342- if (r.second != -1 ) { field += std::to_string (r.second ); }
3343- i++;
3344- }
3345- return std::make_pair (" Range" , field);
3346- }
3347-
3348- inline std::pair<std::string, std::string>
3349- make_basic_authentication_header (const std::string &username,
3350- const std::string &password,
3351- bool is_proxy = false ) {
3352- auto field = " Basic " + detail::base64_encode (username + " :" + password);
3353- auto key = is_proxy ? " Proxy-Authorization" : " Authorization" ;
3354- return std::make_pair (key, field);
3355- }
3356-
3357- inline std::pair<std::string, std::string>
3358- make_bearer_token_authentication_header (const std::string &token,
3359- bool is_proxy = false ) {
3360- auto field = " Bearer " + token;
3361- auto key = is_proxy ? " Proxy-Authorization" : " Authorization" ;
3362- return std::make_pair (key, field);
3363- }
3364-
33653319#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
33663320inline std::pair<std::string, std::string> make_digest_authentication_header (
33673321 const Request &req, const std::map<std::string, std::string> &auth,
@@ -3459,6 +3413,53 @@ inline std::string random_string(size_t length) {
34593413 return str;
34603414}
34613415
3416+ class ContentProviderAdapter {
3417+ public:
3418+ explicit ContentProviderAdapter (
3419+ ContentProviderWithoutLength &&content_provider)
3420+ : content_provider_(content_provider) {}
3421+
3422+ bool operator ()(size_t offset, size_t , DataSink &sink) {
3423+ return content_provider_ (offset, sink);
3424+ }
3425+
3426+ private:
3427+ ContentProviderWithoutLength content_provider_;
3428+ };
3429+
3430+ } // namespace detail
3431+
3432+ // Header utilities
3433+ inline std::pair<std::string, std::string> make_range_header (Ranges ranges) {
3434+ std::string field = " bytes=" ;
3435+ auto i = 0 ;
3436+ for (auto r : ranges) {
3437+ if (i != 0 ) { field += " , " ; }
3438+ if (r.first != -1 ) { field += std::to_string (r.first ); }
3439+ field += ' -' ;
3440+ if (r.second != -1 ) { field += std::to_string (r.second ); }
3441+ i++;
3442+ }
3443+ return std::make_pair (" Range" , field);
3444+ }
3445+
3446+ inline std::pair<std::string, std::string>
3447+ make_basic_authentication_header (const std::string &username,
3448+ const std::string &password,
3449+ bool is_proxy = false ) {
3450+ auto field = " Basic " + detail::base64_encode (username + " :" + password);
3451+ auto key = is_proxy ? " Proxy-Authorization" : " Authorization" ;
3452+ return std::make_pair (key, field);
3453+ }
3454+
3455+ inline std::pair<std::string, std::string>
3456+ make_bearer_token_authentication_header (const std::string &token,
3457+ bool is_proxy = false ) {
3458+ auto field = " Bearer " + token;
3459+ auto key = is_proxy ? " Proxy-Authorization" : " Authorization" ;
3460+ return std::make_pair (key, field);
3461+ }
3462+
34623463// Request implementation
34633464inline bool Request::has_header (const char *key) const {
34643465 return detail::has_header (headers, key);
@@ -3598,7 +3599,7 @@ Response::set_content_provider(const char *content_type,
35983599 const std::function<void ()> &resource_releaser) {
35993600 set_header (" Content-Type" , content_type);
36003601 content_length_ = 0 ;
3601- content_provider_ = ContentProviderAdapter (std::move (provider));
3602+ content_provider_ = detail:: ContentProviderAdapter (std::move (provider));
36023603 content_provider_resource_releaser_ = resource_releaser;
36033604 is_chunked_content_provider = false ;
36043605}
@@ -3608,7 +3609,7 @@ inline void Response::set_chunked_content_provider(
36083609 const std::function<void ()> &resource_releaser) {
36093610 set_header (" Content-Type" , content_type);
36103611 content_length_ = 0 ;
3611- content_provider_ = ContentProviderAdapter (std::move (provider));
3612+ content_provider_ = detail:: ContentProviderAdapter (std::move (provider));
36123613 content_provider_resource_releaser_ = resource_releaser;
36133614 is_chunked_content_provider = true ;
36143615}
@@ -4706,13 +4707,13 @@ inline bool ClientImpl::handle_request(Stream &strm, const Request &req,
47064707
47074708 if (!username.empty () && !password.empty ()) {
47084709 std::map<std::string, std::string> auth;
4709- if (parse_www_authenticate (res, auth, is_proxy)) {
4710+ if (detail:: parse_www_authenticate (res, auth, is_proxy)) {
47104711 Request new_req = req;
47114712 new_req.authorization_count_ += 1 ;
47124713 auto key = is_proxy ? " Proxy-Authorization" : " Authorization" ;
47134714 new_req.headers .erase (key);
4714- new_req.headers .insert (make_digest_authentication_header (
4715- req, auth, new_req.authorization_count_ , random_string (10 ),
4715+ new_req.headers .insert (detail:: make_digest_authentication_header (
4716+ req, auth, new_req.authorization_count_ , detail:: random_string (10 ),
47164717 username, password, is_proxy));
47174718
47184719 Response new_res;
@@ -5811,16 +5812,16 @@ inline bool SSLClient::connect_with_proxy(Socket &socket, Response &res,
58115812 if (!proxy_digest_auth_username_.empty () &&
58125813 !proxy_digest_auth_password_.empty ()) {
58135814 std::map<std::string, std::string> auth;
5814- if (parse_www_authenticate (res2, auth, true )) {
5815+ if (detail:: parse_www_authenticate (res2, auth, true )) {
58155816 Response res3;
58165817 if (!detail::process_client_socket (
58175818 socket.sock , read_timeout_sec_, read_timeout_usec_,
58185819 write_timeout_sec_, write_timeout_usec_, [&](Stream &strm) {
58195820 Request req3;
58205821 req3.method = " CONNECT" ;
58215822 req3.path = host_and_port_;
5822- req3.headers .insert (make_digest_authentication_header (
5823- req3, auth, 1 , random_string (10 ),
5823+ req3.headers .insert (detail:: make_digest_authentication_header (
5824+ req3, auth, 1 , detail:: random_string (10 ),
58245825 proxy_digest_auth_username_, proxy_digest_auth_password_,
58255826 true ));
58265827 return process_request (strm, req3, res3, false );
0 commit comments