25 std::shared_ptr<ccf::RPCMap> rpc_map;
26 std::shared_ptr<ccf::RpcHandler> handler;
27 std::shared_ptr<ccf::SessionContext> session_ctx;
28 std::shared_ptr<ErrorReporter> error_reporter;
33 std::shared_ptr<ccf::RPCMap> rpc_map,
37 std::unique_ptr<ccf::tls::Context> ctx,
39 const std::shared_ptr<ErrorReporter>& error_reporter =
nullptr) :
41 request_parser(*this, configuration),
43 error_reporter(error_reporter),
44 interface_id(interface_id)
47 bool parse(std::span<const uint8_t> data)
override
52 request_parser.
execute(data.data(), data.size());
60 error_reporter->report_request_payload_too_large_error(interface_id);
66 HTTP_STATUS_PAYLOAD_TOO_LARGE,
67 ccf::errors::RequestBodyTooLarge,
76 error_reporter->report_request_header_too_large_error(interface_id);
82 HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE,
83 ccf::errors::RequestHeaderTooLarge,
88 catch (
const std::exception& e)
92 error_reporter->report_parsing_error(interface_id);
97 headers[ccf::http::headers::CONTENT_TYPE] =
98 ccf::http::headervalues::contenttype::TEXT;
102 auto body_s = fmt::format(
103 "Unable to parse data as a HTTP request. Error message is: {}\n"
104 "Error occurred while parsing fragment:\n",
106 std::vector<uint8_t> response_body(
107 std::begin(body_s), std::end(body_s));
108 response_body.insert(response_body.end(), data.begin(), data.end());
111 HTTP_STATUS_BAD_REQUEST,
114 std::move(response_body));
124 const std::string_view& url,
126 std::vector<uint8_t>&& body,
130 "Processing msg({}, {} [{} bytes])",
131 llhttp_method_name(verb),
137 if (session_ctx ==
nullptr)
139 session_ctx = std::make_shared<ccf::SessionContext>(
143 std::shared_ptr<http::HttpRpcContext> rpc_ctx =
nullptr;
146 rpc_ctx = std::make_shared<HttpRpcContext>(
154 catch (std::exception& e)
157 HTTP_STATUS_INTERNAL_SERVER_ERROR,
158 ccf::errors::InternalError,
159 fmt::format(
"Error constructing RpcContext: {}", e.what())});
163 std::shared_ptr<ccf::RpcHandler> search =
164 http::fetch_rpc_handler(rpc_ctx, rpc_map);
166 search->process(rpc_ctx);
168 if (rpc_ctx->response_is_pending)
177 rpc_ctx->get_response_http_status(),
178 rpc_ctx->get_response_headers(),
179 rpc_ctx->get_response_trailers(),
180 std::move(rpc_ctx->get_response_body()));
182 if (rpc_ctx->terminate_session)
188 catch (
const std::exception& e)
191 HTTP_STATUS_INTERNAL_SERVER_ERROR,
192 ccf::errors::InternalError,
193 fmt::format(
"Exception: {}", e.what())});
197 LOG_DEBUG_FMT(
"Closing connection due to exception: {}", e.what());
207 std::span<const uint8_t> body)
override
209 if (!trailers.empty())
211 throw std::logic_error(
"Cannot return trailers over HTTP/1");
215 for (
const auto& [k, v] : headers)
217 response.set_header(k, v);
226 auto data = response.build_response();
227 tls_io->send_raw(data.data(), data.size());
234 throw std::logic_error(
"Not implemented!");
239 throw std::logic_error(
"Not implemented!");
244 throw std::logic_error(
"Not implemented!");
250 throw std::logic_error(
"Not implemented!");
265 std::unique_ptr<ccf::tls::Context> ctx) :
268 response_parser(*this)
271 bool parse(std::span<const uint8_t> data)
override
276 response_parser.
execute(data.data(), data.size());
280 catch (
const std::exception& e)
285 "Error occurred while parsing fragment {} byte fragment:\n{}",
287 std::string_view((
char const*)data.data(), data.size()));
296 auto data = request.build_request();
301 const std::string& hostname,
302 const std::string& service,
306 tls_io->set_handshake_error_cb([e](std::string&& error_msg) {
323 std::vector<uint8_t>&& body)
override
347 response_parser(*this)
350 bool parse(std::span<const uint8_t> data)
override
354 response_parser.
execute(data.data(), data.size());
357 catch (
const std::exception& e)
362 "Error occurred while parsing fragment {} byte fragment:\n{}",
364 std::string_view((
char const*)data.data(), data.size()));
373 auto data = request.build_request();
378 const std::string& hostname,
379 const std::string& service,
389 std::vector<uint8_t>&& body)
override
Definition client_session.h:11
virtual void connect(const std::string &hostname, const std::string &service, const HandleDataCallback f, const HandleErrorCallback e=nullptr)
Definition client_session.h:39
std::function< void(const std::string &error_msg)> HandleErrorCallback
Definition client_session.h:19
std::function< void(ccf::http_status status, http::HeaderMap &&headers, std::vector< uint8_t > &&body)> HandleDataCallback
Definition client_session.h:16
HandleDataCallback handle_data_cb
Definition client_session.h:22
void send_data(std::span< const uint8_t > data) override
Definition session.h:99
void close_session() override
Definition session.h:111
::tcp::ConnID session_id
Definition session.h:86
std::shared_ptr< ccf::TLSSession > tls_io
Definition session.h:85
void send_data(std::span< const uint8_t > data) override
Definition session.h:59
::tcp::ConnID session_id
Definition session.h:161
void close_session() override
Definition session.h:181
Definition http_responder.h:16
bool send_odata_error_response(ccf::ErrorDetails &&error)
Definition http_responder.h:35
Definition http_session.h:257
HTTPClientSession(::tcp::ConnID session_id_, ringbuffer::AbstractWriterFactory &writer_factory, std::unique_ptr< ccf::tls::Context > ctx)
Definition http_session.h:262
void send_request(http::Request &&request) override
Definition http_session.h:294
void handle_response(ccf::http_status status, ccf::http::HeaderMap &&headers, std::vector< uint8_t > &&body) override
Definition http_session.h:320
bool parse(std::span< const uint8_t > data) override
Definition http_session.h:271
void connect(const std::string &hostname, const std::string &service, const HandleDataCallback f, const HandleErrorCallback e) override
Definition http_session.h:300
Definition http_session.h:21
bool send_response(ccf::http_status status_code, ccf::http::HeaderMap &&headers, ccf::http::HeaderMap &&trailers, std::span< const uint8_t > body) override
Definition http_session.h:203
bool set_on_stream_close_callback(ccf::http::StreamOnCloseCallback cb) override
Definition http_session.h:247
bool close_stream(ccf::http::HeaderMap &&) override
Definition http_session.h:242
bool stream_data(std::span< const uint8_t > data) override
Definition http_session.h:237
bool start_stream(ccf::http_status status, const ccf::http::HeaderMap &headers) override
Definition http_session.h:231
void handle_request(llhttp_method verb, const std::string_view &url, ccf::http::HeaderMap &&headers, std::vector< uint8_t > &&body, int32_t) override
Definition http_session.h:122
HTTPServerSession(std::shared_ptr< ccf::RPCMap > rpc_map, ::tcp::ConnID session_id_, const ccf::ListenInterfaceID &interface_id, ringbuffer::AbstractWriterFactory &writer_factory, std::unique_ptr< ccf::tls::Context > ctx, const ccf::http::ParserConfiguration &configuration, const std::shared_ptr< ErrorReporter > &error_reporter=nullptr)
Definition http_session.h:32
bool parse(std::span< const uint8_t > data) override
Definition http_session.h:47
void execute(const uint8_t *data, size_t size)
Definition http_parser.h:221
Definition http_parser.h:394
Definition http_proc.h:20
Definition http_builder.h:118
Definition http_parser.h:452
Definition http_proc.h:31
Definition http_builder.h:200
Definition http_session.h:337
bool parse(std::span< const uint8_t > data) override
Definition http_session.h:350
void send_request(http::Request &&request) override
Definition http_session.h:371
void handle_response(ccf::http_status status, ccf::http::HeaderMap &&headers, std::vector< uint8_t > &&body) override
Definition http_session.h:386
UnencryptedHTTPClientSession(::tcp::ConnID session_id_, ringbuffer::AbstractWriterFactory &writer_factory)
Definition http_session.h:342
void connect(const std::string &hostname, const std::string &service, const HandleDataCallback f, const HandleErrorCallback e) override
Definition http_session.h:377
Definition ring_buffer_types.h:153
#define LOG_TRACE_FMT
Definition logger.h:356
#define LOG_DEBUG_FMT
Definition logger.h:357
#define LOG_FAIL_FMT
Definition logger.h:363
std::map< std::string, std::string, std::less<> > HeaderMap
Definition http_header_map.h:10
std::function< void(void)> StreamOnCloseCallback
Definition http_responder.h:13
std::string ListenInterfaceID
Definition rpc_context.h:21
llhttp_status http_status
Definition http_status.h:9
Definition error_reporter.h:6
int64_t ConnID
Definition msg_types.h:9
Definition odata_error.h:58
Definition http_configuration.h:24