From bf4199f234c7e189e843f30f3ab77c087a95aade Mon Sep 17 00:00:00 2001 From: qicosmos Date: Fri, 31 May 2024 15:55:56 +0800 Subject: [PATCH] fix ssl option (#594) --- include/cinatra/coro_http_client.hpp | 7 ++++++- tests/test_cinatra.cpp | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/cinatra/coro_http_client.hpp b/include/cinatra/coro_http_client.hpp index ce76a357..5f90831b 100644 --- a/include/cinatra/coro_http_client.hpp +++ b/include/cinatra/coro_http_client.hpp @@ -294,7 +294,12 @@ class coro_http_client : public std::enable_shared_from_this { bool no_schema = !has_schema(uri); std::string append_uri; if (no_schema) { - append_uri.append("http://").append(uri); +#ifdef CINATRA_ENABLE_SSL + if (is_ssl_schema_) + append_uri.append("https://").append(uri); + else +#endif + append_uri.append("http://").append(uri); } auto [ok, u] = handle_uri(data, no_schema ? append_uri : uri); diff --git a/tests/test_cinatra.cpp b/tests/test_cinatra.cpp index d1a3139c..24b64eb4 100644 --- a/tests/test_cinatra.cpp +++ b/tests/test_cinatra.cpp @@ -60,6 +60,21 @@ TEST_CASE("test for gzip") { #ifdef CINATRA_ENABLE_SSL TEST_CASE("test ssl client") { + { + coro_http_client client4{}; + client4.set_ssl_schema(true); + auto result = client4.get("www.baidu.com"); + assert(result.status == 200); + + auto lazy = []() -> async_simple::coro::Lazy { + coro_http_client client5{}; + client5.set_ssl_schema(true); + co_await client5.connect("www.baidu.com"); + auto result = co_await client5.async_get("/"); + assert(result.status == 200); + }; + async_simple::coro::syncAwait(lazy()); + } { coro_http_client client{}; auto result = client.get("https://www.bing.com");