Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
yhirose committed Sep 6, 2019
1 parent c923843 commit bfec819
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ if (cli.send(requests, responses)) {
```cpp
httplib::Client cli("yahoo.com");
cli.follow_location(true);
auto ret = cli.Get("/");
auto res = cli.Get("/");
res->status; // 200
```
OpenSSL Support
Expand Down
28 changes: 16 additions & 12 deletions test/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,9 @@ TEST(AbsoluteRedirectTest, Redirect) {
#endif

cli.follow_location(true);
auto ret = cli.Get("/absolute-redirect/3");
ASSERT_TRUE(ret != nullptr);
auto res = cli.Get("/absolute-redirect/3");
ASSERT_TRUE(res != nullptr);
EXPECT_EQ(200, res->status);
}

TEST(RedirectTest, Redirect) {
Expand All @@ -455,8 +456,9 @@ TEST(RedirectTest, Redirect) {
#endif

cli.follow_location(true);
auto ret = cli.Get("/redirect/3");
ASSERT_TRUE(ret != nullptr);
auto res = cli.Get("/redirect/3");
ASSERT_TRUE(res != nullptr);
EXPECT_EQ(200, res->status);
}

TEST(RelativeRedirectTest, Redirect) {
Expand All @@ -469,8 +471,9 @@ TEST(RelativeRedirectTest, Redirect) {
#endif

cli.follow_location(true);
auto ret = cli.Get("/relative-redirect/3");
ASSERT_TRUE(ret != nullptr);
auto res = cli.Get("/relative-redirect/3");
ASSERT_TRUE(res != nullptr);
EXPECT_EQ(200, res->status);
}

TEST(TooManyRedirectTest, Redirect) {
Expand All @@ -483,23 +486,24 @@ TEST(TooManyRedirectTest, Redirect) {
#endif

cli.follow_location(true);
auto ret = cli.Get("/redirect/21");
ASSERT_TRUE(ret == nullptr);
auto res = cli.Get("/redirect/21");
ASSERT_TRUE(res == nullptr);
}

#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
TEST(YahooRedirectTest, Redirect) {
httplib::Client cli("yahoo.com");
cli.follow_location(true);
auto ret = cli.Get("/");
ASSERT_TRUE(ret != nullptr);
auto res = cli.Get("/");
ASSERT_TRUE(res != nullptr);
EXPECT_EQ(200, res->status);
}

TEST(Https2HttpRedirectTest, Redirect) {
httplib::SSLClient cli("httpbin.org");
cli.follow_location(true);
auto ret = cli.Get("/redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302");
ASSERT_TRUE(ret != nullptr);
auto res = cli.Get("/redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302");
ASSERT_TRUE(res != nullptr);
}
#endif

Expand Down

0 comments on commit bfec819

Please sign in to comment.