Handles an HTTP server connection
| 209 | |
| 210 | // Handles an HTTP server connection |
| 211 | void |
| 212 | do_session( |
| 213 | tcp::socket& socket, |
| 214 | std::shared_ptr<std::string const> const& doc_root) |
| 215 | { |
| 216 | beast::error_code ec; |
| 217 | |
| 218 | // This buffer is required to persist across reads |
| 219 | beast::flat_buffer buffer; |
| 220 | |
| 221 | for(;;) |
| 222 | { |
| 223 | // Read a request |
| 224 | http::request<http::string_body> req; |
| 225 | http::read(socket, buffer, req, ec); |
| 226 | if(ec == http::error::end_of_stream) |
| 227 | break; |
| 228 | if(ec) |
| 229 | return fail(ec, "read"); |
| 230 | |
| 231 | // Handle request |
| 232 | http::message_generator msg = |
| 233 | handle_request(*doc_root, std::move(req)); |
| 234 | |
| 235 | // Determine if we should close the connection |
| 236 | bool keep_alive = msg.keep_alive(); |
| 237 | |
| 238 | // Send the response |
| 239 | beast::write(socket, std::move(msg), ec); |
| 240 | |
| 241 | if(ec) |
| 242 | return fail(ec, "write"); |
| 243 | if(! keep_alive) |
| 244 | { |
| 245 | // This means we should close the connection, usually because |
| 246 | // the response indicated the "Connection: close" semantic. |
| 247 | break; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | // Send a TCP shutdown |
| 252 | socket.shutdown(tcp::socket::shutdown_send, ec); |
| 253 | |
| 254 | // At this point the connection is closed gracefully |
| 255 | } |
| 256 | |
| 257 | //------------------------------------------------------------------------------ |
| 258 |
nothing calls this directly
no test coverage detected