MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/xstudio / process_request

Method process_request

extern/include/cpp-httplib/httplib.h:5780–5917  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5778}
5779
5780inline bool
5781Server::process_request(Stream &strm, bool close_connection,
5782 bool &connection_closed,
5783 const std::function<void(Request &)> &setup_request) {
5784 std::array<char, 2048> buf{};
5785
5786 detail::stream_line_reader line_reader(strm, buf.data(), buf.size());
5787
5788 // Connection has been closed on client
5789 if (!line_reader.getline()) { return false; }
5790
5791 Request req;
5792 Response res;
5793
5794 res.version = "HTTP/1.1";
5795
5796 for (const auto &header : default_headers_) {
5797 if (res.headers.find(header.first) == res.headers.end()) {
5798 res.headers.insert(header);
5799 }
5800 }
5801
5802#ifdef _WIN32
5803 // TODO: Increase FD_SETSIZE statically (libzmq), dynamically (MySQL).
5804#else
5805#ifndef CPPHTTPLIB_USE_POLL
5806 // Socket file descriptor exceeded FD_SETSIZE...
5807 if (strm.socket() >= FD_SETSIZE) {
5808 Headers dummy;
5809 detail::read_headers(strm, dummy);
5810 res.status = 500;
5811 return write_response(strm, close_connection, req, res);
5812 }
5813#endif
5814#endif
5815
5816 // Check if the request URI doesn't exceed the limit
5817 if (line_reader.size() > CPPHTTPLIB_REQUEST_URI_MAX_LENGTH) {
5818 Headers dummy;
5819 detail::read_headers(strm, dummy);
5820 res.status = 414;
5821 return write_response(strm, close_connection, req, res);
5822 }
5823
5824 // Request line and headers
5825 if (!parse_request_line(line_reader.ptr(), req) ||
5826 !detail::read_headers(strm, req.headers)) {
5827 res.status = 400;
5828 return write_response(strm, close_connection, req, res);
5829 }
5830
5831 if (req.get_header_value("Connection") == "close") {
5832 connection_closed = true;
5833 }
5834
5835 if (req.version == "HTTP/1.0" &&
5836 req.get_header_value("Connection") != "Keep-Alive") {
5837 connection_closed = true;

Callers

nothing calls this directly

Calls 15

read_headersFunction · 0.85
parse_range_headerFunction · 0.85
status_messageFunction · 0.85
read_contentFunction · 0.85
shutdown_socketFunction · 0.85
close_socketFunction · 0.85
getlineMethod · 0.80
socketMethod · 0.80
ptrMethod · 0.80
get_header_valueMethod · 0.80
set_headerMethod · 0.80

Tested by

no test coverage detected