| 55 | |
| 56 | |
| 57 | void HTTPServerConnection::run() |
| 58 | { |
| 59 | std::string server = _pParams->getSoftwareVersion(); |
| 60 | HTTPServerSession session(socket(), _pParams); |
| 61 | while (!_stopped && session.hasMoreRequests()) |
| 62 | { |
| 63 | try |
| 64 | { |
| 65 | Poco::FastMutex::ScopedLock lock(_mutex); |
| 66 | if (!_stopped) |
| 67 | { |
| 68 | HTTPServerResponseImpl response(session); |
| 69 | HTTPServerRequestImpl request(response, session, _pParams); |
| 70 | |
| 71 | Poco::Timestamp now; |
| 72 | response.setDate(now); |
| 73 | response.setVersion(request.getVersion()); |
| 74 | response.setKeepAlive(_pParams->getKeepAlive() && request.getKeepAlive() && session.canKeepAlive()); |
| 75 | if (!server.empty()) |
| 76 | response.set("Server", server); |
| 77 | try |
| 78 | { |
| 79 | #ifndef POCO_ENABLE_CPP11 |
| 80 | std::auto_ptr<HTTPRequestHandler> pHandler(_pFactory->createRequestHandler(request)); |
| 81 | #else |
| 82 | std::unique_ptr<HTTPRequestHandler> pHandler(_pFactory->createRequestHandler(request)); |
| 83 | #endif |
| 84 | if (pHandler.get()) |
| 85 | { |
| 86 | if (request.getExpectContinue() && response.getStatus() == HTTPResponse::HTTP_OK) |
| 87 | response.sendContinue(); |
| 88 | |
| 89 | pHandler->handleRequest(request, response); |
| 90 | session.setKeepAlive(_pParams->getKeepAlive() && response.getKeepAlive() && session.canKeepAlive()); |
| 91 | |
| 92 | /// all that fuzz is all about to make session close with less timeout than 15s (set in HTTPServerParams c-tor) |
| 93 | if (_pParams->getKeepAlive() && response.getKeepAlive() && session.canKeepAlive()) |
| 94 | { |
| 95 | int value = response.getKeepAliveTimeout(); |
| 96 | if (value < 0) |
| 97 | value = request.getKeepAliveTimeout(); |
| 98 | if (value > 0) |
| 99 | session.setKeepAliveTimeout(Poco::Timespan(value, 0)); |
| 100 | } |
| 101 | |
| 102 | } |
| 103 | else sendErrorResponse(session, HTTPResponse::HTTP_NOT_IMPLEMENTED); |
| 104 | } |
| 105 | catch (Poco::Exception&) |
| 106 | { |
| 107 | if (!response.sent()) |
| 108 | { |
| 109 | try |
| 110 | { |
| 111 | sendErrorResponse(session, HTTPResponse::HTTP_INTERNAL_SERVER_ERROR); |
| 112 | } |
| 113 | catch (...) |
| 114 | { |
nothing calls this directly
no test coverage detected