diff --git a/include/cserver/clients/http/component.hpp b/include/cserver/clients/http/component.hpp index 0e0d32c..40b3d7f 100644 --- a/include/cserver/clients/http/component.hpp +++ b/include/cserver/clients/http/component.hpp @@ -108,26 +108,16 @@ public: boost::asio::ssl::stream socket(this->taskProcessor.ioContext, this->ctx); boost::asio::ip::tcp::resolver::iterator endpoint = co_await this->resolver.async_resolve({request.request.url.host(), request.request.url.has_port() ? request.request.url.port() : request.request.url.scheme()}, boost::asio::use_awaitable); - auto [ec, _] = co_await boost::asio::async_connect(socket.lowest_layer(), endpoint, boost::asio::as_tuple(boost::asio::use_awaitable)); - if(ec) { - throw BoostErrorWrapper{ec}; - }; - co_await socket.async_handshake(boost::asio::ssl::stream_base::client, boost::asio::redirect_error(boost::asio::use_awaitable, ec)); - if(ec) { - throw BoostErrorWrapper{ec}; - }; + co_await boost::asio::async_connect(socket.lowest_layer(), endpoint, boost::asio::use_awaitable); + + co_await socket.async_handshake(boost::asio::ssl::stream_base::client, boost::asio::use_awaitable); + std::string req(request.request.ToString()); - co_await boost::asio::async_write(socket, boost::asio::buffer(req.data(), req.size()), boost::asio::transfer_all(), boost::asio::redirect_error(boost::asio::use_awaitable, ec)); - if(ec) { - throw BoostErrorWrapper{ec}; - }; + co_await boost::asio::async_write(socket, boost::asio::buffer(req.data(), req.size()), boost::asio::transfer_all(), boost::asio::use_awaitable); auto response = co_await this->ReadHeaders(socket, flags...); if constexpr(kUseStreaming) { co_return clients::http::Response, decltype(socket)>{*this, std::move(socket), std::move(response)}; } else { - if(response.statusCode != 200) { - co_return response; - }; if(response.headers.contains("Content-Length")) { auto size = std::stoi(response.headers["Content-Length"]); response.body = co_await ReadBody(std::move(socket), size, flags...); diff --git a/include/cserver/server/http/http_stream.hpp b/include/cserver/server/http/http_stream.hpp index 8bec9ca..5701bfc 100644 --- a/include/cserver/server/http/http_stream.hpp +++ b/include/cserver/server/http/http_stream.hpp @@ -1,6 +1,5 @@ #pragma once #include -#include #include #include @@ -11,17 +10,11 @@ struct HTTPStream { std::stringstream stream = {}; inline auto SetMethod(std::string method) -> Task { method += " "; - auto [ec, n] = co_await boost::asio::async_write(this->socket, boost::asio::buffer(method.data(), method.size()), boost::asio::transfer_all(), boost::asio::as_tuple(boost::asio::use_awaitable)); - if(ec) { - throw BoostErrorWrapper{ec}; - }; + co_await boost::asio::async_write(this->socket, boost::asio::buffer(method.data(), method.size()), boost::asio::transfer_all(), boost::asio::use_awaitable); }; inline auto SetStatus(std::string status) -> Task { status = fmt::format("HTTP/1.1 {}\r\n", std::move(status)); - auto [ec, n] = co_await boost::asio::async_write(this->socket, boost::asio::buffer(status.data(), status.size()), boost::asio::transfer_all(), boost::asio::as_tuple(boost::asio::use_awaitable)); - if(ec) { - throw BoostErrorWrapper{ec}; - }; + co_await boost::asio::async_write(this->socket, boost::asio::buffer(status.data(), status.size()), boost::asio::transfer_all(), boost::asio::use_awaitable); }; inline auto SetHeader(std::string first, std::string second) -> Task { @@ -31,16 +24,10 @@ struct HTTPStream { inline auto SetEndOfHeaders() -> Task { this->stream << "\r\n"; auto str = this->stream.str(); - auto [ec, n] = co_await boost::asio::async_write(this->socket, boost::asio::buffer(str.data(), str.size()), boost::asio::transfer_all(), boost::asio::as_tuple(boost::asio::use_awaitable)); - if(ec) { - throw BoostErrorWrapper{ec}; - }; + co_await boost::asio::async_write(this->socket, boost::asio::buffer(str.data(), str.size()), boost::asio::transfer_all(), boost::asio::use_awaitable); }; inline auto PushBodyChunk(std::string_view chunk) -> Task { - auto [ec, n] = co_await boost::asio::async_write(this->socket, boost::asio::buffer(chunk.data(), chunk.size()), boost::asio::transfer_all(), boost::asio::as_tuple(boost::asio::use_awaitable)); - if(ec) { - throw BoostErrorWrapper{ec}; - }; + co_await boost::asio::async_write(this->socket, boost::asio::buffer(chunk.data(), chunk.size()), boost::asio::transfer_all(), boost::asio::use_awaitable); }; inline auto Close() -> Task { this->socket.close(); diff --git a/include/cserver/utils/boost_error_wrapper.hpp b/include/cserver/utils/boost_error_wrapper.hpp deleted file mode 100644 index 8777262..0000000 --- a/include/cserver/utils/boost_error_wrapper.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include - -namespace cserver { - -struct BoostErrorWrapper : std::exception, boost::system::error_code { - std::string errorMessage; - BoostErrorWrapper(boost::system::error_code ec) : errorMessage(ec.what()) {}; - auto what() const noexcept -> const char* override { - return this->errorMessage.c_str(); - }; -}; - -} // namespace cserver