mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-10 09:43:51 +00:00
Fix #357
This commit is contained in:
parent
6cde600922
commit
797d1f27e8
11
README.md
11
README.md
@ -287,7 +287,6 @@ Client Example
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
// IMPORTANT: 1st parameter must be a hostname or an IP address string.
|
|
||||||
httplib::Client cli("localhost", 1234);
|
httplib::Client cli("localhost", 1234);
|
||||||
|
|
||||||
auto res = cli.Get("/hi");
|
auto res = cli.Get("/hi");
|
||||||
@ -297,6 +296,16 @@ int main(void)
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
NOTE: Constructor with scheme-host-port string is now supported!
|
||||||
|
|
||||||
|
```c++
|
||||||
|
httplib::Client cli("localhost");
|
||||||
|
httplib::Client cli("localhost:8080");
|
||||||
|
httplib::Client cli("http://localhost");
|
||||||
|
httplib::Client cli("http://localhost:8080");
|
||||||
|
httplib::Client cli("https://localhost");
|
||||||
|
```
|
||||||
|
|
||||||
### GET with HTTP headers
|
### GET with HTTP headers
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
|
21
test/test.cc
21
test/test.cc
@ -3065,19 +3065,26 @@ TEST(CleanupTest, WSACleanup) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// #ifndef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
|
// TEST(NoSSLSupport, SimpleInterface) {
|
||||||
|
// httplib::Client cli("https://yahoo.com");
|
||||||
|
// ASSERT_FALSE(cli.is_valid());
|
||||||
|
// }
|
||||||
|
// #endif
|
||||||
|
|
||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
TEST(InvalidScheme, SimpleInterface) {
|
TEST(InvalidScheme, SimpleInterface) {
|
||||||
httplib::Client2 cli("scheme://yahoo.com");
|
httplib::Client cli("scheme://yahoo.com");
|
||||||
ASSERT_FALSE(cli.is_valid());
|
ASSERT_FALSE(cli.is_valid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(NoScheme, SimpleInterface) {
|
TEST(NoScheme, SimpleInterface) {
|
||||||
httplib::Client2 cli("yahoo.com");
|
httplib::Client cli("yahoo.com:80");
|
||||||
ASSERT_FALSE(cli.is_valid());
|
ASSERT_TRUE(cli.is_valid());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YahooRedirectTest2, SimpleInterface) {
|
TEST(YahooRedirectTest2, SimpleInterface) {
|
||||||
httplib::Client2 cli("http://yahoo.com");
|
httplib::Client cli("http://yahoo.com");
|
||||||
|
|
||||||
auto res = cli.Get("/");
|
auto res = cli.Get("/");
|
||||||
ASSERT_TRUE(res != nullptr);
|
ASSERT_TRUE(res != nullptr);
|
||||||
@ -3090,7 +3097,7 @@ TEST(YahooRedirectTest2, SimpleInterface) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(YahooRedirectTest3, SimpleInterface) {
|
TEST(YahooRedirectTest3, SimpleInterface) {
|
||||||
httplib::Client2 cli("https://yahoo.com");
|
httplib::Client cli("https://yahoo.com");
|
||||||
|
|
||||||
auto res = cli.Get("/");
|
auto res = cli.Get("/");
|
||||||
ASSERT_TRUE(res != nullptr);
|
ASSERT_TRUE(res != nullptr);
|
||||||
@ -3104,7 +3111,7 @@ TEST(YahooRedirectTest3, SimpleInterface) {
|
|||||||
|
|
||||||
#ifdef CPPHTTPLIB_BROTLI_SUPPORT
|
#ifdef CPPHTTPLIB_BROTLI_SUPPORT
|
||||||
TEST(DecodeWithChunkedEncoding, BrotliEncoding) {
|
TEST(DecodeWithChunkedEncoding, BrotliEncoding) {
|
||||||
httplib::Client2 cli("https://cdnjs.cloudflare.com");
|
httplib::Client cli("https://cdnjs.cloudflare.com");
|
||||||
auto res = cli.Get("/ajax/libs/jquery/3.5.1/jquery.js", {{"Accept-Encoding", "brotli"}});
|
auto res = cli.Get("/ajax/libs/jquery/3.5.1/jquery.js", {{"Accept-Encoding", "brotli"}});
|
||||||
|
|
||||||
ASSERT_TRUE(res != nullptr);
|
ASSERT_TRUE(res != nullptr);
|
||||||
@ -3117,7 +3124,7 @@ TEST(DecodeWithChunkedEncoding, BrotliEncoding) {
|
|||||||
#if 0
|
#if 0
|
||||||
TEST(HttpsToHttpRedirectTest2, SimpleInterface) {
|
TEST(HttpsToHttpRedirectTest2, SimpleInterface) {
|
||||||
auto res =
|
auto res =
|
||||||
httplib::Client2("https://httpbin.org")
|
httplib::Client("https://httpbin.org")
|
||||||
.set_follow_location(true)
|
.set_follow_location(true)
|
||||||
.Get("/redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302");
|
.Get("/redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302");
|
||||||
|
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace httplib;
|
using namespace httplib;
|
||||||
|
|
||||||
void ProxyTest(Client& cli, bool basic) {
|
template <typename T>
|
||||||
|
void ProxyTest(T& cli, bool basic) {
|
||||||
cli.set_proxy("localhost", basic ? 3128 : 3129);
|
cli.set_proxy("localhost", basic ? 3128 : 3129);
|
||||||
auto res = cli.Get("/get");
|
auto res = cli.Get("/get");
|
||||||
ASSERT_TRUE(res != nullptr);
|
ASSERT_TRUE(res != nullptr);
|
||||||
@ -36,7 +37,8 @@ TEST(ProxyTest, SSLDigest) {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void RedirectProxyText(Client& cli, const char *path, bool basic) {
|
template <typename T>
|
||||||
|
void RedirectProxyText(T& cli, const char *path, bool basic) {
|
||||||
cli.set_proxy("localhost", basic ? 3128 : 3129);
|
cli.set_proxy("localhost", basic ? 3128 : 3129);
|
||||||
if (basic) {
|
if (basic) {
|
||||||
cli.set_proxy_basic_auth("hello", "world");
|
cli.set_proxy_basic_auth("hello", "world");
|
||||||
@ -100,7 +102,8 @@ TEST(RedirectTest, YouTubeSSLDigest) {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BaseAuthTestFromHTTPWatch(Client& cli) {
|
template <typename T>
|
||||||
|
void BaseAuthTestFromHTTPWatch(T& cli) {
|
||||||
cli.set_proxy("localhost", 3128);
|
cli.set_proxy("localhost", 3128);
|
||||||
cli.set_proxy_basic_auth("hello", "world");
|
cli.set_proxy_basic_auth("hello", "world");
|
||||||
|
|
||||||
@ -157,7 +160,8 @@ TEST(BaseAuthTest, SSL) {
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
void DigestAuthTestFromHTTPWatch(Client& cli) {
|
template <typename T>
|
||||||
|
void DigestAuthTestFromHTTPWatch(T& cli) {
|
||||||
cli.set_proxy("localhost", 3129);
|
cli.set_proxy("localhost", 3129);
|
||||||
cli.set_proxy_digest_auth("hello", "world");
|
cli.set_proxy_digest_auth("hello", "world");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user