static void didReceiveResponse(CFURLConnectionRef conn, CFURLResponseRef cfResponse, const void* clientInfo) { #if LOG_DISABLED UNUSED_PARAM(conn); #endif ResourceHandle* handle = static_cast<ResourceHandle*>(const_cast<void*>(clientInfo)); LOG(Network, "CFNet - didReceiveResponse(conn=%p, handle=%p) (%s)", conn, handle, handle->firstRequest().url().string().utf8().data()); if (!handle->client()) return; #if PLATFORM(MAC) // Avoid MIME type sniffing if the response comes back as 304 Not Modified. CFHTTPMessageRef msg = wkGetCFURLResponseHTTPResponse(cfResponse); int statusCode = msg ? CFHTTPMessageGetResponseStatusCode(msg) : 0; if (statusCode != 304) adjustMIMETypeIfNecessary(cfResponse); if (_CFURLRequestCopyProtocolPropertyForKey(handle->firstRequest().cfURLRequest(), CFSTR("ForceHTMLMIMEType"))) wkSetCFURLResponseMIMEType(cfResponse, CFSTR("text/html")); #else if (!CFURLResponseGetMIMEType(cfResponse)) { // We should never be applying the default MIMEType if we told the networking layer to do content sniffing for handle. ASSERT(!handle->shouldContentSniff()); setDefaultMIMEType(cfResponse); } #endif handle->client()->didReceiveResponse(handle, cfResponse); }
void SynchronousResourceHandleCFURLConnectionDelegate::didReceiveResponse(CFURLResponseRef cfResponse) { LOG(Network, "CFNet - SynchronousResourceHandleCFURLConnectionDelegate::didReceiveResponse(handle=%p) (%s)", m_handle, m_handle->firstRequest().url().string().utf8().data()); if (!m_handle->client()) return; #if PLATFORM(COCOA) // Avoid MIME type sniffing if the response comes back as 304 Not Modified. CFHTTPMessageRef msg = wkGetCFURLResponseHTTPResponse(cfResponse); int statusCode = msg ? CFHTTPMessageGetResponseStatusCode(msg) : 0; if (statusCode != 304) adjustMIMETypeIfNecessary(cfResponse); #if !PLATFORM(IOS) if (_CFURLRequestCopyProtocolPropertyForKey(m_handle->firstRequest().cfURLRequest(DoNotUpdateHTTPBody), CFSTR("ForceHTMLMIMEType"))) wkSetCFURLResponseMIMEType(cfResponse, CFSTR("text/html")); #endif // !PLATFORM(IOS) #else if (!CFURLResponseGetMIMEType(cfResponse)) { // We should never be applying the default MIMEType if we told the networking layer to do content sniffing for handle. ASSERT(!m_handle->shouldContentSniff()); setDefaultMIMEType(cfResponse); } #endif #if USE(QUICK_LOOK) m_handle->setQuickLookHandle(QuickLookHandle::create(m_handle, this, cfResponse)); if (m_handle->quickLookHandle()) cfResponse = m_handle->quickLookHandle()->cfResponse(); #endif m_handle->client()->didReceiveResponse(m_handle, cfResponse); }
void ResourceRequest::doUpdateResourceRequest() { if (!m_cfRequest) { *this = ResourceRequest(); return; } m_url = CFURLRequestGetURL(m_cfRequest.get()); m_cachePolicy = (ResourceRequestCachePolicy)CFURLRequestGetCachePolicy(m_cfRequest.get()); m_timeoutInterval = CFURLRequestGetTimeoutInterval(m_cfRequest.get()); m_firstPartyForCookies = CFURLRequestGetMainDocumentURL(m_cfRequest.get()); if (CFStringRef method = CFURLRequestCopyHTTPRequestMethod(m_cfRequest.get())) { m_httpMethod = method; CFRelease(method); } m_allowCookies = CFURLRequestShouldHandleHTTPCookies(m_cfRequest.get()); if (httpPipeliningEnabled()) m_priority = toResourceLoadPriority(wkGetHTTPPipeliningPriority(m_cfRequest.get())); m_httpHeaderFields.clear(); if (CFDictionaryRef headers = CFURLRequestCopyAllHTTPHeaderFields(m_cfRequest.get())) { CFIndex headerCount = CFDictionaryGetCount(headers); Vector<const void*, 128> keys(headerCount); Vector<const void*, 128> values(headerCount); CFDictionaryGetKeysAndValues(headers, keys.data(), values.data()); for (int i = 0; i < headerCount; ++i) m_httpHeaderFields.set((CFStringRef)keys[i], (CFStringRef)values[i]); CFRelease(headers); } m_responseContentDispositionEncodingFallbackArray.clear(); RetainPtr<CFArrayRef> encodingFallbacks(AdoptCF, copyContentDispositionEncodingFallbackArray(m_cfRequest.get())); if (encodingFallbacks) { CFIndex count = CFArrayGetCount(encodingFallbacks.get()); for (CFIndex i = 0; i < count; ++i) { CFStringEncoding encoding = reinterpret_cast<CFIndex>(CFArrayGetValueAtIndex(encodingFallbacks.get(), i)); if (encoding != kCFStringEncodingInvalidId) m_responseContentDispositionEncodingFallbackArray.append(CFStringConvertEncodingToIANACharSetName(encoding)); } } #if ENABLE(CACHE_PARTITIONING) RetainPtr<CFStringRef> cachePartition(AdoptCF, static_cast<CFStringRef>(_CFURLRequestCopyProtocolPropertyForKey(m_cfRequest.get(), wkCachePartitionKey()))); if (cachePartition) m_cachePartition = cachePartition.get(); #endif }
void SynchronousResourceHandleCFURLConnectionDelegate::didReceiveResponse(CFURLConnectionRef connection, CFURLResponseRef cfResponse) { LOG(Network, "CFNet - SynchronousResourceHandleCFURLConnectionDelegate::didReceiveResponse(handle=%p) (%s)", m_handle, m_handle->firstRequest().url().string().utf8().data()); if (!m_handle->client()) return; #if PLATFORM(COCOA) // Avoid MIME type sniffing if the response comes back as 304 Not Modified. auto msg = CFURLResponseGetHTTPResponse(cfResponse); int statusCode = msg ? CFHTTPMessageGetResponseStatusCode(msg) : 0; if (statusCode != 304) { bool isMainResourceLoad = m_handle->firstRequest().requester() == ResourceRequest::Requester::Main; adjustMIMETypeIfNecessary(cfResponse, isMainResourceLoad); } #if !PLATFORM(IOS) if (_CFURLRequestCopyProtocolPropertyForKey(m_handle->firstRequest().cfURLRequest(DoNotUpdateHTTPBody), CFSTR("ForceHTMLMIMEType"))) CFURLResponseSetMIMEType(cfResponse, CFSTR("text/html")); #endif // !PLATFORM(IOS) #else if (!CFURLResponseGetMIMEType(cfResponse)) adjustMIMETypeIfNecessary(cfResponse); if (!CFURLResponseGetMIMEType(cfResponse)) { // We should never be applying the default MIMEType if we told the networking layer to do content sniffing for handle. ASSERT(!m_handle->shouldContentSniff()); setDefaultMIMEType(cfResponse); } #endif #if USE(QUICK_LOOK) m_handle->setQuickLookHandle(QuickLookHandle::create(m_handle, this, cfResponse)); if (m_handle->quickLookHandle()) cfResponse = m_handle->quickLookHandle()->cfResponse(); #endif ResourceResponse resourceResponse(cfResponse); #if PLATFORM(COCOA) && ENABLE(WEB_TIMING) ResourceHandle::getConnectionTimingData(connection, resourceResponse.networkLoadTiming()); #else UNUSED_PARAM(connection); #endif m_handle->client()->didReceiveResponse(m_handle, WTFMove(resourceResponse)); }
void ResourceRequest::doUpdateResourceRequest() { if (!m_cfRequest) { #if PLATFORM(IOS) // <rdar://problem/9913526> // This is a hack to mimic the subtle behaviour of the Foundation based ResourceRequest // code. That code does not reset m_httpMethod if the NSURLRequest is nil. I filed // <https://bugs.webkit.org/show_bug.cgi?id=66336> to track that. // Another related bug is <https://bugs.webkit.org/show_bug.cgi?id=66350>. Fixing that // would, ideally, allow us to not have this hack. But unfortunately that caused layout test // failures. // Removal of this hack is tracked by <rdar://problem/9970499>. String httpMethod = m_httpMethod; *this = ResourceRequest(); m_httpMethod = httpMethod; #else *this = ResourceRequest(); #endif return; } m_url = CFURLRequestGetURL(m_cfRequest.get()); m_cachePolicy = (ResourceRequestCachePolicy)CFURLRequestGetCachePolicy(m_cfRequest.get()); m_timeoutInterval = CFURLRequestGetTimeoutInterval(m_cfRequest.get()); m_firstPartyForCookies = CFURLRequestGetMainDocumentURL(m_cfRequest.get()); if (CFStringRef method = CFURLRequestCopyHTTPRequestMethod(m_cfRequest.get())) { m_httpMethod = method; CFRelease(method); } m_allowCookies = CFURLRequestShouldHandleHTTPCookies(m_cfRequest.get()); if (resourcePrioritiesEnabled()) m_priority = toResourceLoadPriority(CFURLRequestGetRequestPriority(m_cfRequest.get())); m_httpHeaderFields.clear(); if (CFDictionaryRef headers = CFURLRequestCopyAllHTTPHeaderFields(m_cfRequest.get())) { CFIndex headerCount = CFDictionaryGetCount(headers); Vector<const void*, 128> keys(headerCount); Vector<const void*, 128> values(headerCount); CFDictionaryGetKeysAndValues(headers, keys.data(), values.data()); for (int i = 0; i < headerCount; ++i) m_httpHeaderFields.set((CFStringRef)keys[i], (CFStringRef)values[i]); CFRelease(headers); } m_responseContentDispositionEncodingFallbackArray.clear(); RetainPtr<CFArrayRef> encodingFallbacks = adoptCF(copyContentDispositionEncodingFallbackArray(m_cfRequest.get())); if (encodingFallbacks) { CFIndex count = CFArrayGetCount(encodingFallbacks.get()); for (CFIndex i = 0; i < count; ++i) { CFStringEncoding encoding = reinterpret_cast<CFIndex>(CFArrayGetValueAtIndex(encodingFallbacks.get(), i)); if (encoding != kCFStringEncodingInvalidId) m_responseContentDispositionEncodingFallbackArray.append(CFStringConvertEncodingToIANACharSetName(encoding)); } } #if ENABLE(CACHE_PARTITIONING) RetainPtr<CFStringRef> cachePartition = adoptCF(static_cast<CFStringRef>(_CFURLRequestCopyProtocolPropertyForKey(m_cfRequest.get(), wkCachePartitionKey()))); if (cachePartition) m_cachePartition = cachePartition.get(); #endif }