bool HttpHeaders::isKeepAlive(const HttpMessage& message) { const std::string& connection = message.getHeader(Names::CONNECTION); if (boost::algorithm::iequals(Values::CLOSE, connection)) { return false; } if (message.getProtocolVersion().isKeepAliveDefault()) { return !boost::algorithm::iequals(Values::CLOSE, connection); } else { return boost::algorithm::iequals(Values::KEEP_ALIVE, connection); } }
void HttpHeaders::setKeepAlive(HttpMessage& message, bool keepAlive) { if (message.getProtocolVersion().isKeepAliveDefault()) { if (keepAlive) { message.removeHeader(Names::CONNECTION); } else { message.setHeader(Names::CONNECTION, Values::CLOSE); } } else { if (keepAlive) { message.setHeader(Names::CONNECTION, Values::KEEP_ALIVE); } else { message.removeHeader(Names::CONNECTION); } } }