Skip to content

Commit 9a7b36a

Browse files
authored
fix ssl option (#687)
1 parent 9c7cffe commit 9a7b36a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

include/ylt/standalone/cinatra/coro_http_client.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,12 @@ class coro_http_client : public std::enable_shared_from_this<coro_http_client> {
294294
bool no_schema = !has_schema(uri);
295295
std::string append_uri;
296296
if (no_schema) {
297-
append_uri.append("http://").append(uri);
297+
#ifdef CINATRA_ENABLE_SSL
298+
if (is_ssl_schema_)
299+
append_uri.append("https://").append(uri);
300+
else
301+
#endif
302+
append_uri.append("http://").append(uri);
298303
}
299304

300305
auto [ok, u] = handle_uri(data, no_schema ? append_uri : uri);

src/coro_http/examples/example.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,17 @@ async_simple::coro::Lazy<void> basic_usage() {
424424
co_await client3.connect("https://www.baidu.com");
425425
result = co_await client3.async_get("/");
426426
assert(result.status == 200);
427+
428+
coro_http_client client4{};
429+
client4.set_ssl_schema(true);
430+
result = client4.get("www.baidu.com");
431+
assert(result.status == 200);
432+
433+
coro_http_client client5{};
434+
client5.set_ssl_schema(true);
435+
co_await client5.connect("www.baidu.com");
436+
result = co_await client5.async_get("/");
437+
assert(result.status == 200);
427438
#endif
428439
}
429440

0 commit comments

Comments
 (0)