Skip to content

Commit a1cfc0f

Browse files
committed
Fixed problem with redirect
1 parent eb4fcb5 commit a1cfc0f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

httplib.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,17 +2477,17 @@ inline std::pair<std::string, std::string> make_range_header(Ranges ranges) {
24772477

24782478
inline std::pair<std::string, std::string>
24792479
make_basic_authentication_header(const std::string &username,
2480-
const std::string &password, bool proxy = false) {
2480+
const std::string &password, bool is_proxy = false) {
24812481
auto field = "Basic " + detail::base64_encode(username + ":" + password);
2482-
auto key = proxy ? "Proxy-Authorization" : "Authorization";
2482+
auto key = is_proxy ? "Proxy-Authorization" : "Authorization";
24832483
return std::make_pair(key, field);
24842484
}
24852485

24862486
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
24872487
inline std::pair<std::string, std::string> make_digest_authentication_header(
24882488
const Request &req, const std::map<std::string, std::string> &auth,
24892489
size_t cnonce_count, const std::string &cnonce, const std::string &username,
2490-
const std::string &password, bool proxy = false) {
2490+
const std::string &password, bool is_proxy = false) {
24912491
using namespace std;
24922492

24932493
string nc;
@@ -2527,15 +2527,15 @@ inline std::pair<std::string, std::string> make_digest_authentication_header(
25272527
"\", algorithm=" + algo + ", qop=" + qop + ", nc=\"" + nc +
25282528
"\", cnonce=\"" + cnonce + "\", response=\"" + response + "\"";
25292529

2530-
auto key = proxy ? "Proxy-Authorization" : "Authorization";
2530+
auto key = is_proxy ? "Proxy-Authorization" : "Authorization";
25312531
return std::make_pair(key, field);
25322532
}
25332533
#endif
25342534

25352535
inline bool parse_www_authenticate(const httplib::Response &res,
25362536
std::map<std::string, std::string> &auth,
2537-
bool proxy) {
2538-
auto key = proxy ? "Proxy-Authenticate" : "WWW-Authenticate";
2537+
bool is_proxy) {
2538+
auto key = is_proxy ? "Proxy-Authenticate" : "WWW-Authenticate";
25392539
if (res.has_header(key)) {
25402540
static auto re = std::regex(R"~((?:(?:,\s*)?(.+?)=(?:"(.*?)"|([^,]*))))~");
25412541
auto s = res.get_header_value(key);
@@ -3562,6 +3562,8 @@ inline bool Client::send(const Request &req, Response &res) {
35623562
std::map<std::string, std::string> auth;
35633563
if (parse_www_authenticate(res, auth, is_proxy)) {
35643564
Request new_req = req;
3565+
auto key = is_proxy ? "Proxy-Authorization" : "WWW-Authorization";
3566+
new_req.headers.erase(key);
35653567
new_req.headers.insert(make_digest_authentication_header(
35663568
req, auth, 1, random_string(10), username, password, is_proxy));
35673569

0 commit comments

Comments
 (0)