Exemplo n.º 1
0
int HttpHeaders::getContentLength(const HttpMessage& message, int defaultValue) {
    std::string contentLength = message.getHeader(Names::CONTENT_LENGTH);
    if (!contentLength.empty()) {
        return Integer::parse(contentLength);
    }

    // WebSockset messages have constant content-lengths.
    const HttpRequest* request =
        dynamic_cast<const HttpRequest*>(&message);
    if (NULL != request) {
        if (HttpMethod::HM_GET.equals(request->getMethod()) &&
            request->containsHeader(Names::SEC_WEBSOCKET_KEY1) &&
            request->containsHeader(Names::SEC_WEBSOCKET_KEY2)) {
            return 8;
        }
    }
    
    const HttpResponse* response =
        dynamic_cast<const HttpResponse*>(&message);
    if (NULL != response) {
        if (response->getStatus().getCode() == 101 &&
            response->containsHeader(Names::SEC_WEBSOCKET_ORIGIN) &&
            response->containsHeader(Names::SEC_WEBSOCKET_LOCATION)) {
                return 16;
        }
    }

    return defaultValue;
}
Exemplo n.º 2
0
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);
    }
}