From 03a5cf865be4576b342bcdbe1e584d6bfb220e0a Mon Sep 17 00:00:00 2001 From: qicosmos Date: Mon, 22 Jul 2024 15:20:56 +0800 Subject: [PATCH] default port (#617) --- include/cinatra/coro_http_client.hpp | 19 ++++++++++--------- include/cinatra/uri.hpp | 4 ++-- include/cinatra/version.hpp | 2 +- lang/coro_http_client_introduction.md | 2 +- tests/test_cinatra.cpp | 2 +- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/cinatra/coro_http_client.hpp b/include/cinatra/coro_http_client.hpp index 063ccb68..2a84efab 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_); } } 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/include/cinatra/version.hpp b/include/cinatra/version.hpp index 4ba2c29f..57eddccd 100644 --- a/include/cinatra/version.hpp +++ b/include/cinatra/version.hpp @@ -5,4 +5,4 @@ // CINATRA_VERSION % 100 is the sub-minor version // CINATRA_VERSION / 100 % 1000 is the minor version // CINATRA_VERSION / 100000 is the major version -#define CINATRA_VERSION 901 // 0.9.1 \ No newline at end of file +#define CINATRA_VERSION 902 // 0.9.2 \ No newline at end of file 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"));