MCPcopy Create free account
hub / github.com/FastFlowLM/FastFlowLM / read_request

Method read_request

src/server/server.cpp:208–247  ·  view source on GitHub ↗

@brief read request

Source from the content-addressed store, hash-verified

206
207///@brief read request
208void HttpSession::read_request(bool cors) {
209 auto self = shared_from_this();
210
211 // Use a parser to control the maximum accepted body size
212 auto parser = std::make_shared<http::request_parser<http::string_body>>();
213 parser->body_limit(self->server_.get_max_body_size_bytes());
214
215 http::async_read(self->socket_, self->buffer_, *parser,
216 [self, parser, cors](beast::error_code ec, std::size_t bytes_transferred) {
217 if (!ec) {
218 header_print("TCP", "Read " + std::to_string(bytes_transferred) + " bytes from socket");
219 // Move the parsed message into our request object
220 self->req_ = parser->release();
221 self->handle_request(cors);
222 return;
223 }
224
225 // Handle body too large explicitly with 413
226 if (ec == http::error::body_limit) {
227 self->res_ = {};
228 self->res_.version(11);
229 self->res_.result(http::status::payload_too_large);
230 self->res_.set(http::field::content_type, "application/json");
231 self->res_.keep_alive(false);
232 json err = {{"error", "Request payload too large"}, {"max_bytes", self->server_.get_max_body_size_bytes()}};
233 self->res_.body() = err.dump();
234 self->res_.prepare_payload();
235 self->write_response();
236 return;
237 }
238
239 // Connection closed or other error, decrement connection counter
240 try {
241 header_print("🔒 ", "TCP connection closed - Remote: " + self->socket_.remote_endpoint().address().to_string() + ":" + std::to_string(self->socket_.remote_endpoint().port()));
242 } catch (...) {
243 header_print("🔒 ", "TCP connection closed - Remote endpoint unavailable");
244 }
245 self->server_.active_connections_.fetch_sub(1);
246 });
247}
248
249///@brief handle request
250

Callers 1

handle_requestMethod · 0.95

Calls 7

handle_requestMethod · 0.95
write_responseMethod · 0.95
releaseMethod · 0.80
to_stringFunction · 0.50
setMethod · 0.45
dumpMethod · 0.45

Tested by

no test coverage detected