From 4a61f68fa4a59ca97c0da1024a4b96d1aafbc0d2 Mon Sep 17 00:00:00 2001 From: Jiwoo Park Date: Sat, 17 Jun 2023 03:56:16 +0900 Subject: [PATCH] Don't overwrite the last redirected location (#1589) * Don't overwrite the last redirected location * Check the last redirected location --- httplib.h | 3 ++- test/test.cc | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/httplib.h b/httplib.h index 05544a7..ea42f14 100644 --- a/httplib.h +++ b/httplib.h @@ -3920,7 +3920,8 @@ inline bool redirect(T &cli, Request &req, Response &res, if (ret) { req = new_req; res = new_res; - res.location = location; + + if (res.location.empty()) res.location = location; } return ret; } diff --git a/test/test.cc b/test/test.cc index 43d3f41..c182bb1 100644 --- a/test/test.cc +++ b/test/test.cc @@ -972,7 +972,7 @@ TEST(YahooRedirectTest, Redirect_Online) { res = cli.Get("/"); ASSERT_TRUE(res); EXPECT_EQ(200, res->status); - EXPECT_EQ("https://yahoo.com/", res->location); + EXPECT_EQ("https://www.yahoo.com/", res->location); } TEST(HttpsToHttpRedirectTest, Redirect_Online) { @@ -5301,7 +5301,7 @@ TEST(YahooRedirectTest2, SimpleInterface_Online) { res = cli.Get("/"); ASSERT_TRUE(res); EXPECT_EQ(200, res->status); - EXPECT_EQ("https://yahoo.com/", res->location); + EXPECT_EQ("https://www.yahoo.com/", res->location); } TEST(YahooRedirectTest3, SimpleInterface_Online) {