| 6039 | } |
| 6040 | |
| 6041 | inline bool |
| 6042 | Server::process_request(Stream &strm, bool close_connection, |
| 6043 | bool &connection_closed, |
| 6044 | const std::function<void(Request &)> &setup_request) { |
| 6045 | std::array<char, 2048> buf{}; |
| 6046 | |
| 6047 | detail::stream_line_reader line_reader(strm, buf.data(), buf.size()); |
| 6048 | |
| 6049 | // Connection has been closed on client |
| 6050 | if (!line_reader.getline()) { return false; } |
| 6051 | |
| 6052 | Request req; |
| 6053 | Response res; |
| 6054 | |
| 6055 | res.version = "HTTP/1.1"; |
| 6056 | |
| 6057 | for (const auto &header : default_headers_) { |
| 6058 | if (res.headers.find(header.first) == res.headers.end()) { |
| 6059 | res.headers.insert(header); |
| 6060 | } |
| 6061 | } |
| 6062 | |
| 6063 | #ifdef _WIN32 |
| 6064 | // TODO: Increase FD_SETSIZE statically (libzmq), dynamically (MySQL). |
| 6065 | #else |
| 6066 | #ifndef CPPHTTPLIB_USE_POLL |
| 6067 | // Socket file descriptor exceeded FD_SETSIZE... |
| 6068 | if (strm.socket() >= FD_SETSIZE) { |
| 6069 | Headers dummy; |
| 6070 | detail::read_headers(strm, dummy); |
| 6071 | res.status = 500; |
| 6072 | return write_response(strm, close_connection, req, res); |
| 6073 | } |
| 6074 | #endif |
| 6075 | #endif |
| 6076 | |
| 6077 | // Check if the request URI doesn't exceed the limit |
| 6078 | if (line_reader.size() > CPPHTTPLIB_REQUEST_URI_MAX_LENGTH) { |
| 6079 | Headers dummy; |
| 6080 | detail::read_headers(strm, dummy); |
| 6081 | res.status = 414; |
| 6082 | return write_response(strm, close_connection, req, res); |
| 6083 | } |
| 6084 | |
| 6085 | // Request line and headers |
| 6086 | if (!parse_request_line(line_reader.ptr(), req) || |
| 6087 | !detail::read_headers(strm, req.headers)) { |
| 6088 | res.status = 400; |
| 6089 | return write_response(strm, close_connection, req, res); |
| 6090 | } |
| 6091 | |
| 6092 | if (req.get_header_value("Connection") == "close") { |
| 6093 | connection_closed = true; |
| 6094 | } |
| 6095 | |
| 6096 | if (req.version == "HTTP/1.0" && |
| 6097 | req.get_header_value("Connection") != "Keep-Alive") { |
| 6098 | connection_closed = true; |
nothing calls this directly
no test coverage detected