void ResourceResponse::updateFromSoupMessage(SoupMessage* soupMessage)
{
    SoupURI* soupURI = soup_message_get_uri(soupMessage);
    GOwnPtr<gchar> uri(soup_uri_to_string(soupURI, FALSE));
    m_url = KURL(KURL(), String::fromUTF8(uri.get()));

    m_httpStatusCode = soupMessage->status_code;

    SoupMessageHeadersIter headersIter;
    const char* headerName;
    const char* headerValue;

    soup_message_headers_iter_init(&headersIter, soupMessage->response_headers);
    while (soup_message_headers_iter_next(&headersIter, &headerName, &headerValue))
        m_httpHeaderFields.set(String::fromUTF8(headerName), String::fromUTF8(headerValue));

    m_soupFlags = soup_message_get_flags(soupMessage);

    String contentType = soup_message_headers_get_one(soupMessage->response_headers, "Content-Type");
    setMimeType(extractMIMETypeFromMediaType(contentType));

    setTextEncodingName(extractCharsetFromMediaType(contentType));
    setExpectedContentLength(soup_message_headers_get_content_length(soupMessage->response_headers));
    setHTTPStatusText(soupMessage->reason_phrase);
    setSuggestedFilename(filenameFromHTTPContentDisposition(httpHeaderField("Content-Disposition")));
}
ResourceResponse::ResourceResponse(CrossThreadResourceResponseData* data)
    : ResourceResponse()
{
    setURL(data->m_url);
    setMimeType(AtomicString(data->m_mimeType));
    setExpectedContentLength(data->m_expectedContentLength);
    setTextEncodingName(AtomicString(data->m_textEncodingName));
    setSuggestedFilename(data->m_suggestedFilename);

    setHTTPStatusCode(data->m_httpStatusCode);
    setHTTPStatusText(AtomicString(data->m_httpStatusText));

    m_httpHeaderFields.adopt(data->m_httpHeaders.release());
    setLastModifiedDate(data->m_lastModifiedDate);
    setResourceLoadTiming(data->m_resourceLoadTiming.release());
    m_securityInfo = data->m_securityInfo;
    m_hasMajorCertificateErrors = data->m_hasMajorCertificateErrors;
    m_securityStyle = data->m_securityStyle;
    m_securityDetails.protocol = data->m_securityDetails.protocol;
    m_securityDetails.cipher = data->m_securityDetails.cipher;
    m_securityDetails.keyExchange = data->m_securityDetails.keyExchange;
    m_securityDetails.mac = data->m_securityDetails.mac;
    m_securityDetails.certID = data->m_securityDetails.certID;
    m_httpVersion = data->m_httpVersion;
    m_appCacheID = data->m_appCacheID;
    m_appCacheManifestURL = data->m_appCacheManifestURL.copy();
    m_isMultipartPayload = data->m_isMultipartPayload;
    m_wasFetchedViaSPDY = data->m_wasFetchedViaSPDY;
    m_wasNpnNegotiated = data->m_wasNpnNegotiated;
    m_wasAlternateProtocolAvailable = data->m_wasAlternateProtocolAvailable;
    m_wasFetchedViaProxy = data->m_wasFetchedViaProxy;
    m_wasFetchedViaServiceWorker = data->m_wasFetchedViaServiceWorker;
    m_wasFallbackRequiredByServiceWorker = data->m_wasFallbackRequiredByServiceWorker;
    m_serviceWorkerResponseType = data->m_serviceWorkerResponseType;
    m_originalURLViaServiceWorker = data->m_originalURLViaServiceWorker;
    m_responseTime = data->m_responseTime;
    m_remoteIPAddress = AtomicString(data->m_remoteIPAddress);
    m_remotePort = data->m_remotePort;
    m_downloadedFilePath = data->m_downloadedFilePath;
    m_downloadedFileHandle = data->m_downloadedFileHandle;

    // Bug https://bugs.webkit.org/show_bug.cgi?id=60397 this doesn't support
    // whatever values may be present in the opaque m_extraData structure.
}
Esempio n. 3
0
void ResourceResponse::updateFromSoupMessageHeaders(const SoupMessageHeaders* messageHeaders)
{
    SoupMessageHeaders* headers = const_cast<SoupMessageHeaders*>(messageHeaders);
    SoupMessageHeadersIter headersIter;
    const char* headerName;
    const char* headerValue;

    // updateFromSoupMessage could be called several times for the same ResourceResponse object,
    // thus, we need to clear old header values and update m_httpHeaderFields from soupMessage headers.
    m_httpHeaderFields.clear();

    soup_message_headers_iter_init(&headersIter, headers);
    while (soup_message_headers_iter_next(&headersIter, &headerName, &headerValue)) {
        String headerNameString = String::fromUTF8WithLatin1Fallback(headerName, strlen(headerName));
        HTTPHeaderMap::const_iterator it = m_httpHeaderFields.find(headerNameString);
        if (it == m_httpHeaderFields.end() || (it != m_httpHeaderFields.end() && it->value.isEmpty()))
            m_httpHeaderFields.set(headerNameString, String::fromUTF8WithLatin1Fallback(headerValue, strlen(headerValue)));
        else {
            StringBuilder builder;
            builder.append(it->value);
            builder.appendLiteral(", ");
            builder.append(String::fromUTF8WithLatin1Fallback(headerValue, strlen(headerValue)));
            m_httpHeaderFields.set(headerNameString, builder.toString());
        }
    }

    String contentType;
    const char* officialType = soup_message_headers_get_one(headers, "Content-Type");
    if (!m_sniffedContentType.isEmpty() && m_sniffedContentType != officialType)
        contentType = m_sniffedContentType;
    else
        contentType = officialType;
    setMimeType(extractMIMETypeFromMediaType(contentType));
    setTextEncodingName(extractCharsetFromMediaType(contentType));

    setExpectedContentLength(soup_message_headers_get_content_length(headers));
    setSuggestedFilename(filenameFromHTTPContentDisposition(httpHeaderField("Content-Disposition")));}