| 16 | } |
| 17 | |
| 18 | void HTTPServerConnection::run() |
| 19 | { |
| 20 | std::string server = params->getSoftwareVersion(); |
| 21 | Poco::Net::HTTPServerSession session(socket(), params); |
| 22 | |
| 23 | while (!stopped && session.hasMoreRequests()) |
| 24 | { |
| 25 | try |
| 26 | { |
| 27 | std::unique_lock<std::mutex> lock(mutex); |
| 28 | if (!stopped) |
| 29 | { |
| 30 | HTTPServerResponse response(session); |
| 31 | HTTPServerRequest request(context, response, session); |
| 32 | |
| 33 | Poco::Timestamp now; |
| 34 | response.setDate(now); |
| 35 | response.setVersion(request.getVersion()); |
| 36 | response.setKeepAlive(params->getKeepAlive() && request.getKeepAlive() && session.canKeepAlive()); |
| 37 | if (!server.empty()) |
| 38 | response.set("Server", server); |
| 39 | try |
| 40 | { |
| 41 | std::unique_ptr<HTTPRequestHandler> handler(factory->createRequestHandler(request)); |
| 42 | |
| 43 | if (handler) |
| 44 | { |
| 45 | if (request.getExpectContinue() && response.getStatus() == Poco::Net::HTTPResponse::HTTP_OK) |
| 46 | response.sendContinue(); |
| 47 | |
| 48 | handler->handleRequest(request, response); |
| 49 | session.setKeepAlive(params->getKeepAlive() && response.getKeepAlive() && session.canKeepAlive()); |
| 50 | } |
| 51 | else |
| 52 | sendErrorResponse(session, Poco::Net::HTTPResponse::HTTP_NOT_IMPLEMENTED); |
| 53 | } |
| 54 | catch (Poco::Exception &) |
| 55 | { |
| 56 | if (!response.sent()) |
| 57 | { |
| 58 | try |
| 59 | { |
| 60 | sendErrorResponse(session, Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR); |
| 61 | } |
| 62 | catch (...) |
| 63 | { |
| 64 | } |
| 65 | } |
| 66 | throw; |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | catch (const Poco::Net::NoMessageException &) |
| 71 | { |
| 72 | break; |
| 73 | } |
| 74 | catch (const Poco::Net::MessageException &) |
| 75 | { |
nothing calls this directly
no test coverage detected