From e6eebd495996c1b71840e8293fc58b6a5f9cc4c7 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Mon, 22 Jul 2024 15:03:00 +0800 Subject: [PATCH] default port --- include/cinatra/coro_http_client.hpp | 21 +++++++++++---------- include/cinatra/uri.hpp | 4 ++-- lang/coro_http_client_introduction.md | 2 +- tests/test_cinatra.cpp | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/cinatra/coro_http_client.hpp b/include/cinatra/coro_http_client.hpp index 063ccb68..239e1217 100644 --- a/include/cinatra/coro_http_client.hpp +++ b/include/cinatra/coro_http_client.hpp @@ -1546,20 +1546,21 @@ class coro_http_client : public std::enable_shared_from_this { if (!proxy_host_.empty() && !proxy_port_.empty()) { if (!proxy_request_uri_.empty()) proxy_request_uri_.clear(); - if (u.get_port() == "http") { - proxy_request_uri_ += "http://" + u.get_host() + ":"; - proxy_request_uri_ += "80"; + if (u.get_port() == "80") { + proxy_request_uri_.append("http://").append(u.get_host()).append(":80"); } - else if (u.get_port() == "https") { - proxy_request_uri_ += "https://" + u.get_host() + ":"; - proxy_request_uri_ += "443"; + else if (u.get_port() == "443") { + proxy_request_uri_.append("https://") + .append(u.get_host()) + .append(":443"); } else { // all be http - proxy_request_uri_ += "http://" + u.get_host() + ":"; - proxy_request_uri_ += u.get_port(); + proxy_request_uri_.append("http://") + .append(u.get_host()) + .append(u.get_port()); } - proxy_request_uri_ += u.get_path(); + proxy_request_uri_.append(u.get_path()); u.path = std::string_view(proxy_request_uri_); } } @@ -2424,7 +2425,7 @@ class coro_http_client : public std::enable_shared_from_this { bool enable_follow_redirect_ = false; bool enable_timeout_ = false; std::chrono::steady_clock::duration conn_timeout_duration_ = - std::chrono::seconds(30); + std::chrono::seconds(8); std::chrono::steady_clock::duration req_timeout_duration_ = std::chrono::seconds(60); bool enable_tcp_no_delay_ = true; diff --git a/include/cinatra/uri.hpp b/include/cinatra/uri.hpp index 4c1aedaa..089ce4b3 100644 --- a/include/cinatra/uri.hpp +++ b/include/cinatra/uri.hpp @@ -232,7 +232,7 @@ class uri_t { std::string port_str; if (is_ssl) { if (port.empty()) { - port_str = "https"; + port_str = "443"; } else { port_str = std::string(port); @@ -240,7 +240,7 @@ class uri_t { } else { if (port.empty()) { - port_str = "http"; + port_str = "80"; } else { port_str = std::string(port); diff --git a/lang/coro_http_client_introduction.md b/lang/coro_http_client_introduction.md index 9bcdebc6..8e74f3b2 100644 --- a/lang/coro_http_client_introduction.md +++ b/lang/coro_http_client_introduction.md @@ -252,7 +252,7 @@ async_simple::coro::Lazy test_async_client() { // 通过重连复用client1 r = async_simple::coro::syncAwait(client1.connect("http://cn.bing.com")); CHECK(client1.get_host() == "cn.bing.com"); - CHECK(client1.get_port() == "http"); + CHECK(client1.get_port() == "80"); CHECK(r.status == 200); ``` diff --git a/tests/test_cinatra.cpp b/tests/test_cinatra.cpp index 08c3de7c..d066acfa 100644 --- a/tests/test_cinatra.cpp +++ b/tests/test_cinatra.cpp @@ -753,7 +753,7 @@ TEST_CASE("test coro_http_client async_http_connect") { r = async_simple::coro::syncAwait(client1.connect("http://cn.bing.com")); CHECK(client1.get_host() == "cn.bing.com"); - CHECK(client1.get_port() == "http"); + CHECK(client1.get_port() == "80"); CHECK(r.status >= 200); r = async_simple::coro::syncAwait(client1.connect("http://www.baidu.com"));