| 6129 | } |
| 6130 | |
| 6131 | inline bool ClientImpl::handle_request(Stream& strm, Request& req, |
| 6132 | Response& res, bool close_connection, |
| 6133 | Error& error) { |
| 6134 | if (req.path.empty()) { |
| 6135 | error = Error::Connection; |
| 6136 | return false; |
| 6137 | } |
| 6138 | |
| 6139 | auto req_save = req; |
| 6140 | |
| 6141 | bool ret; |
| 6142 | |
| 6143 | if (!is_ssl() && !proxy_host_.empty() && proxy_port_ != -1) { |
| 6144 | auto req2 = req; |
| 6145 | req2.path = "http://" + host_and_port_ + req.path; |
| 6146 | ret = process_request(strm, req2, res, close_connection, error); |
| 6147 | req = req2; |
| 6148 | req.path = req_save.path; |
| 6149 | } |
| 6150 | else { |
| 6151 | ret = process_request(strm, req, res, close_connection, error); |
| 6152 | } |
| 6153 | |
| 6154 | if (!ret) { return false; } |
| 6155 | |
| 6156 | if (300 < res.status && res.status < 400 && follow_location_) { |
| 6157 | req = req_save; |
| 6158 | ret = redirect(req, res, error); |
| 6159 | } |
| 6160 | |
| 6161 | #ifdef CPPHTTPLIB_OPENSSL_SUPPORT |
| 6162 | if ((res.status == 401 || res.status == 407) && |
| 6163 | req.authorization_count_ < 5) { |
| 6164 | auto is_proxy = res.status == 407; |
| 6165 | const auto& username = |
| 6166 | is_proxy ? proxy_digest_auth_username_ : digest_auth_username_; |
| 6167 | const auto& password = |
| 6168 | is_proxy ? proxy_digest_auth_password_ : digest_auth_password_; |
| 6169 | |
| 6170 | if (!username.empty() && !password.empty()) { |
| 6171 | std::map<std::string, std::string> auth; |
| 6172 | if (detail::parse_www_authenticate(res, auth, is_proxy)) { |
| 6173 | Request new_req = req; |
| 6174 | new_req.authorization_count_ += 1; |
| 6175 | new_req.headers.erase(is_proxy ? "Proxy-Authorization" |
| 6176 | : "Authorization"); |
| 6177 | new_req.headers.insert(detail::make_digest_authentication_header( |
| 6178 | req, auth, new_req.authorization_count_, detail::random_string(10), |
| 6179 | username, password, is_proxy)); |
| 6180 | |
| 6181 | Response new_res; |
| 6182 | |
| 6183 | ret = send(new_req, new_res, error); |
| 6184 | if (ret) { res = new_res; } |
| 6185 | } |
| 6186 | } |
| 6187 | } |
| 6188 | #endif |
nothing calls this directly
no test coverage detected