From 1ad99bd5f21bc3f94c3faecbdfdc276efef847bc Mon Sep 17 00:00:00 2001 From: qicosmos Date: Wed, 13 Nov 2024 15:00:34 +0800 Subject: [PATCH] add ut for upload --- .../standalone/cinatra/coro_http_client.hpp | 6 +--- src/coro_http/tests/test_cinatra.cpp | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/include/ylt/standalone/cinatra/coro_http_client.hpp b/include/ylt/standalone/cinatra/coro_http_client.hpp index 249293d95..8a4bea234 100644 --- a/include/ylt/standalone/cinatra/coro_http_client.hpp +++ b/include/ylt/standalone/cinatra/coro_http_client.hpp @@ -1538,6 +1538,7 @@ class coro_http_client : public std::enable_shared_from_this { // all be http proxy_request_uri_.append("http://") .append(u.get_host()) + .append(":") .append(u.get_port()); } proxy_request_uri_.append(u.get_path()); @@ -2103,11 +2104,6 @@ class coro_http_client : public std::enable_shared_from_this { .append(CRCF); } - std::error_code ec; - if (!std::filesystem::exists(part.filename, ec)) { - co_return resp_data{ - std::make_error_code(std::errc::no_such_file_or_directory), 404}; - } part_content_head.append(CRCF); } else { diff --git a/src/coro_http/tests/test_cinatra.cpp b/src/coro_http/tests/test_cinatra.cpp index 8ef6af7c8..1da322242 100644 --- a/src/coro_http/tests/test_cinatra.cpp +++ b/src/coro_http/tests/test_cinatra.cpp @@ -1713,6 +1713,29 @@ TEST_CASE("test coro_http_client chunked upload and download") { }); server.async_start(); + { + coro_http_client client{}; + std::string uri = "http://###127.0.0.1:8090/chunked_upload"; + std::string filename = "test_chunked_upload.txt"; + auto lazy = client.async_upload_chunked(uri, http_method::PUT, filename); + auto result = async_simple::coro::syncAwait(lazy); + CHECK(result.status != 200); + + uri = "http://127.0.0.1:8090/chunked_upload"; + filename = "no_such.txt"; + auto lazy1 = client.async_upload_chunked(uri, http_method::PUT, filename); + result = async_simple::coro::syncAwait(lazy1); + CHECK(result.status != 200); + + std::shared_ptr file = nullptr; + uri = "http://127.0.0.1:8090/chunked_upload"; + auto lazy2 = client.async_upload_chunked(uri, http_method::PUT, file); + result = async_simple::coro::syncAwait(lazy2); + CHECK(result.status != 200); + + auto code = async_simple::coro::syncAwait(client.handle_shake()); + CHECK(code); + } auto sizes = {1024 * 1024, 2'000'000, 1024, 100, 0}; for (auto size : sizes) { std::string filename = "test_chunked_upload.txt"; @@ -1982,6 +2005,16 @@ TEST_CASE("test coro http proxy request") { result = async_simple::coro::syncAwait(client.async_get(uri)); if (!result.net_err) CHECK(result.status >= 200); + + client.set_proxy("106.14.255.124", "80"); + uri = "http://www.baidu.com:443"; + result = async_simple::coro::syncAwait(client.async_get(uri)); + CHECK(result.status != 200); + + client.set_proxy("106.14.255.124", "80"); + uri = "http://www.baidu.com:12345"; + result = async_simple::coro::syncAwait(client.async_get(uri)); + CHECK(result.status != 200); } TEST_CASE("test coro http proxy request with port") {