Skip to content

Commit f559823

Browse files
committed
Fixed many redirects problem on Proxy
1 parent 0105865 commit f559823

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

httplib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ struct Request {
333333
MultipartFormData get_file_value(const char *key) const;
334334

335335
// private members...
336-
size_t authorization_count_ = 1;
336+
size_t authorization_count_ = 0;
337337
};
338338

339339
struct Response {
@@ -3995,7 +3995,7 @@ inline bool Client::handle_request(Stream &strm, const Request &req,
39953995

39963996
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
39973997
if ((res.status == 401 || res.status == 407) &&
3998-
req.authorization_count_ == 1) {
3998+
req.authorization_count_ < 5) {
39993999
auto is_proxy = res.status == 407;
40004000
const auto &username =
40014001
is_proxy ? proxy_digest_auth_username_ : digest_auth_username_;

test/test_proxy.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,17 @@ void DigestAuthTestFromHTTPWatch(Client& cli) {
185185
for (auto path : paths) {
186186
auto res = cli.Get(path.c_str());
187187
ASSERT_TRUE(res != nullptr);
188-
EXPECT_EQ(400, res->status);
188+
EXPECT_EQ(401, res->status);
189189
}
190190

191-
cli.set_digest_auth("bad", "world");
192-
for (auto path : paths) {
193-
auto res = cli.Get(path.c_str());
194-
ASSERT_TRUE(res != nullptr);
195-
EXPECT_EQ(400, res->status);
196-
}
191+
// NOTE: Until httpbin.org fixes issue #46, the following test is commented
192+
// out. Plese see https://httpbin.org/digest-auth/auth/hello/world
193+
// cli.set_digest_auth("bad", "world");
194+
// for (auto path : paths) {
195+
// auto res = cli.Get(path.c_str());
196+
// ASSERT_TRUE(res != nullptr);
197+
// EXPECT_EQ(401, res->status);
198+
// }
197199
}
198200
}
199201

@@ -266,7 +268,7 @@ void KeepAliveTest(Client& cli, bool basic) {
266268

267269

268270
{
269-
int count = paths.size();
271+
int count = static_cast<int>(paths.size());
270272
while (count--) {
271273
auto &res = responses[i++];
272274
EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n", res.body);

0 commit comments

Comments
 (0)