Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ssl option #594

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion include/cinatra/coro_http_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,12 @@ class coro_http_client : public std::enable_shared_from_this<coro_http_client> {
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);
Expand Down
15 changes: 15 additions & 0 deletions tests/test_cinatra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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");
Expand Down
Loading