| 5631 | } |
| 5632 | |
| 5633 | inline bool |
| 5634 | Server::process_request(Stream &strm, bool close_connection, |
| 5635 | bool &connection_closed, |
| 5636 | const std::function<void(Request &)> &setup_request) { |
| 5637 | std::array<char, 2048> buf{}; |
| 5638 | |
| 5639 | detail::stream_line_reader line_reader(strm, buf.data(), buf.size()); |
| 5640 | |
| 5641 | // Connection has been closed on client |
| 5642 | if (!line_reader.getline()) { return false; } |
| 5643 | |
| 5644 | Request req; |
| 5645 | Response res; |
| 5646 | |
| 5647 | res.version = "HTTP/1.1"; |
| 5648 | |
| 5649 | for (const auto &header : default_headers_) { |
| 5650 | if (res.headers.find(header.first) == res.headers.end()) { |
| 5651 | res.headers.insert(header); |
| 5652 | } |
| 5653 | } |
| 5654 | |
| 5655 | #ifdef _WIN32 |
| 5656 | // TODO: Increase FD_SETSIZE statically (libzmq), dynamically (MySQL). |
| 5657 | #else |
| 5658 | #ifndef CPPHTTPLIB_USE_POLL |
| 5659 | // Socket file descriptor exceeded FD_SETSIZE... |
| 5660 | if (strm.socket() >= FD_SETSIZE) { |
| 5661 | Headers dummy; |
| 5662 | detail::read_headers(strm, dummy); |
| 5663 | res.status = 500; |
| 5664 | return write_response(strm, close_connection, req, res); |
| 5665 | } |
| 5666 | #endif |
| 5667 | #endif |
| 5668 | |
| 5669 | // Check if the request URI doesn't exceed the limit |
| 5670 | if (line_reader.size() > CPPHTTPLIB_REQUEST_URI_MAX_LENGTH) { |
| 5671 | Headers dummy; |
| 5672 | detail::read_headers(strm, dummy); |
| 5673 | res.status = 414; |
| 5674 | return write_response(strm, close_connection, req, res); |
| 5675 | } |
| 5676 | |
| 5677 | // Request line and headers |
| 5678 | if (!parse_request_line(line_reader.ptr(), req) || |
| 5679 | !detail::read_headers(strm, req.headers)) { |
| 5680 | res.status = 400; |
| 5681 | return write_response(strm, close_connection, req, res); |
| 5682 | } |
| 5683 | |
| 5684 | if (req.get_header_value("Connection") == "close") { |
| 5685 | connection_closed = true; |
| 5686 | } |
| 5687 | |
| 5688 | if (req.version == "HTTP/1.0" && |
| 5689 | req.get_header_value("Connection") != "Keep-Alive") { |
| 5690 | connection_closed = true; |
nothing calls this directly
no test coverage detected