Skip to content

Commit

Permalink
add ut for upload
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Nov 13, 2024
1 parent d20261f commit 1ad99bd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
6 changes: 1 addition & 5 deletions include/ylt/standalone/cinatra/coro_http_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,7 @@ class coro_http_client : public std::enable_shared_from_this<coro_http_client> {
// all be http
proxy_request_uri_.append("http://")
.append(u.get_host())
.append(":")
.append(u.get_port());
}
proxy_request_uri_.append(u.get_path());
Expand Down Expand Up @@ -2103,11 +2104,6 @@ class coro_http_client : public std::enable_shared_from_this<coro_http_client> {
.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 {
Expand Down
33 changes: 33 additions & 0 deletions src/coro_http/tests/test_cinatra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::ifstream> 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";
Expand Down Expand Up @@ -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") {
Expand Down

0 comments on commit 1ad99bd

Please sign in to comment.