diff options
Diffstat (limited to 'Source/WebCore/platform/network/cf/ResourceResponseCFNet.cpp')
-rw-r--r-- | Source/WebCore/platform/network/cf/ResourceResponseCFNet.cpp | 89 |
1 files changed, 54 insertions, 35 deletions
diff --git a/Source/WebCore/platform/network/cf/ResourceResponseCFNet.cpp b/Source/WebCore/platform/network/cf/ResourceResponseCFNet.cpp index d4a0b31..06cc706 100644 --- a/Source/WebCore/platform/network/cf/ResourceResponseCFNet.cpp +++ b/Source/WebCore/platform/network/cf/ResourceResponseCFNet.cpp @@ -42,6 +42,11 @@ using namespace std; namespace WebCore { +static CFStringRef const commonHeaderFields[] = { + CFSTR("Age"), CFSTR("Cache-Control"), CFSTR("Date"), CFSTR("Etag"), CFSTR("Expires"), CFSTR("Last-Modified"), CFSTR("Pragma") +}; +static const int numCommonHeaderFields = sizeof(commonHeaderFields) / sizeof(CFStringRef); + CFURLResponseRef ResourceResponse::cfURLResponse() const { if (!m_cfResponse && !m_isNull) { @@ -70,52 +75,66 @@ static time_t toTimeT(CFAbsoluteTime time) return min(max(minTimeAsDouble, time + kCFAbsoluteTimeIntervalSince1970), maxTimeAsDouble); } -void ResourceResponse::platformLazyInit() +void ResourceResponse::platformLazyInit(InitLevel initLevel) { - if (m_isUpToDate) + if (m_initLevel > initLevel) return; - m_isUpToDate = true; if (m_isNull) { ASSERT(!m_cfResponse.get()); return; } - // FIXME: We may need to do MIME type sniffing here (unless that is done in CFURLResponseGetMIMEType). - - m_url = CFURLResponseGetURL(m_cfResponse.get()); - m_mimeType = CFURLResponseGetMIMEType(m_cfResponse.get()); - m_expectedContentLength = CFURLResponseGetExpectedContentLength(m_cfResponse.get()); - m_textEncodingName = CFURLResponseGetTextEncodingName(m_cfResponse.get()); - - // Workaround for <rdar://problem/8757088>, can be removed once that is fixed. - unsigned textEncodingNameLength = m_textEncodingName.length(); - if (textEncodingNameLength >= 2 && m_textEncodingName[0U] == '"' && m_textEncodingName[textEncodingNameLength - 1] == '"') - m_textEncodingName = m_textEncodingName.substring(1, textEncodingNameLength - 2); - - m_lastModifiedDate = toTimeT(CFURLResponseGetLastModifiedDate(m_cfResponse.get())); - - RetainPtr<CFStringRef> suggestedFilename(AdoptCF, CFURLResponseCopySuggestedFilename(m_cfResponse.get())); - m_suggestedFilename = suggestedFilename.get(); - - CFHTTPMessageRef httpResponse = CFURLResponseGetHTTPResponse(m_cfResponse.get()); - if (httpResponse) { - m_httpStatusCode = CFHTTPMessageGetResponseStatusCode(httpResponse); + if (m_initLevel < CommonFieldsOnly && initLevel >= CommonFieldsOnly) { + m_url = CFURLResponseGetURL(m_cfResponse.get()); + m_mimeType = CFURLResponseGetMIMEType(m_cfResponse.get()); + m_expectedContentLength = CFURLResponseGetExpectedContentLength(m_cfResponse.get()); + m_textEncodingName = CFURLResponseGetTextEncodingName(m_cfResponse.get()); + + // Workaround for <rdar://problem/8757088>, can be removed once that is fixed. + unsigned textEncodingNameLength = m_textEncodingName.length(); + if (textEncodingNameLength >= 2 && m_textEncodingName[0U] == '"' && m_textEncodingName[textEncodingNameLength - 1] == '"') + m_textEncodingName = m_textEncodingName.substring(1, textEncodingNameLength - 2); + + m_lastModifiedDate = toTimeT(CFURLResponseGetLastModifiedDate(m_cfResponse.get())); + + RetainPtr<CFStringRef> suggestedFilename(AdoptCF, CFURLResponseCopySuggestedFilename(m_cfResponse.get())); + m_suggestedFilename = suggestedFilename.get(); + + CFHTTPMessageRef httpResponse = CFURLResponseGetHTTPResponse(m_cfResponse.get()); + if (httpResponse) { + m_httpStatusCode = CFHTTPMessageGetResponseStatusCode(httpResponse); + + RetainPtr<CFDictionaryRef> headers(AdoptCF, CFHTTPMessageCopyAllHeaderFields(httpResponse)); + + for (int i = 0; i < numCommonHeaderFields; i++) { + CFStringRef value; + if (CFDictionaryGetValueIfPresent(headers.get(), commonHeaderFields[i], (const void **)&value)) + m_httpHeaderFields.set(commonHeaderFields[i], value); + } + } else + m_httpStatusCode = 0; + } - RetainPtr<CFStringRef> statusLine(AdoptCF, CFHTTPMessageCopyResponseStatusLine(httpResponse)); - m_httpStatusText = extractReasonPhraseFromHTTPStatusLine(statusLine.get()); + if (m_initLevel < AllFields && initLevel >= AllFields) { + CFHTTPMessageRef httpResponse = CFURLResponseGetHTTPResponse(m_cfResponse.get()); + if (httpResponse) { + RetainPtr<CFStringRef> statusLine(AdoptCF, CFHTTPMessageCopyResponseStatusLine(httpResponse)); + m_httpStatusText = extractReasonPhraseFromHTTPStatusLine(statusLine.get()); + + RetainPtr<CFDictionaryRef> headers(AdoptCF, CFHTTPMessageCopyAllHeaderFields(httpResponse)); + CFIndex headerCount = CFDictionaryGetCount(headers.get()); + Vector<const void*, 128> keys(headerCount); + Vector<const void*, 128> values(headerCount); + CFDictionaryGetKeysAndValues(headers.get(), keys.data(), values.data()); + for (int i = 0; i < headerCount; ++i) + m_httpHeaderFields.set((CFStringRef)keys[i], (CFStringRef)values[i]); + } + } - RetainPtr<CFDictionaryRef> headers(AdoptCF, CFHTTPMessageCopyAllHeaderFields(httpResponse)); - CFIndex headerCount = CFDictionaryGetCount(headers.get()); - Vector<const void*, 128> keys(headerCount); - Vector<const void*, 128> values(headerCount); - CFDictionaryGetKeysAndValues(headers.get(), keys.data(), values.data()); - for (int i = 0; i < headerCount; ++i) - m_httpHeaderFields.set((CFStringRef)keys[i], (CFStringRef)values[i]); - } else - m_httpStatusCode = 0; + m_initLevel = initLevel; } - + bool ResourceResponse::platformCompare(const ResourceResponse& a, const ResourceResponse& b) { return CFEqual(a.cfURLResponse(), b.cfURLResponse()); |