| 5725 | } |
| 5726 | |
| 5727 | inline bool |
| 5728 | Server::process_request(Stream& strm, bool close_connection, |
| 5729 | bool& connection_closed, |
| 5730 | const std::function<void(Request&)>& setup_request) { |
| 5731 | std::array<char, 2048> buf{}; |
| 5732 | |
| 5733 | detail::stream_line_reader line_reader(strm, buf.data(), buf.size()); |
| 5734 | |
| 5735 | // Connection has been closed on client |
| 5736 | if (!line_reader.getline()) { return false; } |
| 5737 | |
| 5738 | Request req; |
| 5739 | Response res; |
| 5740 | |
| 5741 | res.version = "HTTP/1.1"; |
| 5742 | |
| 5743 | for (const auto& header : default_headers_) { |
| 5744 | if (res.headers.find(header.first) == res.headers.end()) { |
| 5745 | res.headers.insert(header); |
| 5746 | } |
| 5747 | } |
| 5748 | |
| 5749 | #ifdef _WIN32 |
| 5750 | // TODO: Increase FD_SETSIZE statically (libzmq), dynamically (MySQL). |
| 5751 | #else |
| 5752 | #ifndef CPPHTTPLIB_USE_POLL |
| 5753 | // Socket file descriptor exceeded FD_SETSIZE... |
| 5754 | if (strm.socket() >= FD_SETSIZE) { |
| 5755 | Headers dummy; |
| 5756 | detail::read_headers(strm, dummy); |
| 5757 | res.status = 500; |
| 5758 | return write_response(strm, close_connection, req, res); |
| 5759 | } |
| 5760 | #endif |
| 5761 | #endif |
| 5762 | |
| 5763 | // Check if the request URI doesn't exceed the limit |
| 5764 | if (line_reader.size() > CPPHTTPLIB_REQUEST_URI_MAX_LENGTH) { |
| 5765 | Headers dummy; |
| 5766 | detail::read_headers(strm, dummy); |
| 5767 | res.status = 414; |
| 5768 | return write_response(strm, close_connection, req, res); |
| 5769 | } |
| 5770 | |
| 5771 | // Request line and headers |
| 5772 | if (!parse_request_line(line_reader.ptr(), req) || |
| 5773 | !detail::read_headers(strm, req.headers)) { |
| 5774 | res.status = 400; |
| 5775 | return write_response(strm, close_connection, req, res); |
| 5776 | } |
| 5777 | |
| 5778 | if (req.get_header_value("Connection") == "close") { |
| 5779 | connection_closed = true; |
| 5780 | } |
| 5781 | |
| 5782 | if (req.version == "HTTP/1.0" && |
| 5783 | req.get_header_value("Connection") != "Keep-Alive") { |
| 5784 | connection_closed = true; |
nothing calls this directly
no test coverage detected