void ResourceLoader::didReceiveResponse( const WebURLResponse& response, std::unique_ptr<WebDataConsumerHandle> handle) { DCHECK(!response.isNull()); m_fetcher->didReceiveResponse(m_resource.get(), response.toResourceResponse(), std::move(handle)); }
void ResourceHandleInternal::willSendRequest( WebURLLoader*, WebURLRequest& request, const WebURLResponse& response) { ASSERT(m_client); ASSERT(!request.isNull()); ASSERT(!response.isNull()); m_client->willSendRequest(m_owner, request.toMutableResourceRequest(), response.toResourceResponse()); }
void printResponseDescription(WebTestDelegate* delegate, const WebURLResponse& response) { if (response.isNull()) { delegate->printMessage("(null)"); return; } string url = response.url().spec(); char data[100]; snprintf(data, sizeof(data), "%d", response. httpStatusCode()); delegate->printMessage(string("<NSURLResponse ") + descriptionSuitableForTestResult(url) + ", http status code " + data + ">"); }
static void printResponseDescription(const WebURLResponse& response) { if (response.isNull()) { fputs("(null)", stdout); return; } string url = response.url().spec(); printf("<NSURLResponse %s, http status code %d>", descriptionSuitableForTestResult(url).c_str(), response.httpStatusCode()); }
void ResourceHandleInternal::didReceiveResponse(WebURLLoader*, const WebURLResponse& response) { ASSERT(m_client); ASSERT(!response.isNull()); bool isMultipart = response.isMultipartPayload(); bool isValidStateTransition = (m_state == ConnectionStateStarted || m_state == ConnectionStateReceivedResponse); // In the case of multipart loads, calls to didReceiveData & didReceiveResponse can be interleaved. if (!isMultipart && !isValidStateTransition) CRASH(); m_state = ConnectionStateReceivedResponse; m_client->didReceiveResponse(m_owner, response.toResourceResponse()); }
void WebViewHost::willSendRequest(WebFrame*, unsigned identifier, WebURLRequest& request, const WebURLResponse& redirectResponse) { // Need to use GURL for host() and SchemeIs() GURL url = request.url(); string requestURL = url.possibly_invalid_spec(); if (layoutTestController()->shouldDumpResourceLoadCallbacks()) { GURL mainDocumentURL = request.firstPartyForCookies(); printResourceDescription(identifier); printf(" - willSendRequest <NSURLRequest URL %s, main document URL %s," " http method %s> redirectResponse ", descriptionSuitableForTestResult(requestURL).c_str(), URLDescription(mainDocumentURL).c_str(), request.httpMethod().utf8().data()); printResponseDescription(redirectResponse); fputs("\n", stdout); } if (!redirectResponse.isNull() && m_blocksRedirects) { fputs("Returning null for this redirect\n", stdout); // To block the request, we set its URL to an empty one. request.setURL(WebURL()); return; } if (m_requestReturnNull) { // To block the request, we set its URL to an empty one. request.setURL(WebURL()); return; } string host = url.host(); // 255.255.255.255 is used in some tests that expect to get back an error. if (!host.empty() && (url.SchemeIs("http") || url.SchemeIs("https")) && host != "127.0.0.1" && host != "255.255.255.255" && host != "localhost" && !m_shell->allowExternalPages()) { printf("Blocked access to external URL %s\n", requestURL.c_str()); // To block the request, we set its URL to an empty one. request.setURL(WebURL()); return; } HashSet<String>::const_iterator end = m_clearHeaders.end(); for (HashSet<String>::const_iterator header = m_clearHeaders.begin(); header != end; ++header) request.clearHTTPHeaderField(WebString(header->characters(), header->length())); // Set the new substituted URL. request.setURL(webkit_support::RewriteLayoutTestsURL(request.url().spec())); }
bool ResourceLoader::willFollowRedirect( WebURLRequest& passedNewRequest, const WebURLResponse& passedRedirectResponse) { DCHECK(!passedNewRequest.isNull()); DCHECK(!passedRedirectResponse.isNull()); if (m_isCacheAwareLoadingActivated) { // Fail as cache miss if cached response is a redirect. didFail( ResourceError::cacheMissError(m_resource->lastResourceRequest().url())); return false; } ResourceRequest& newRequest(passedNewRequest.toMutableResourceRequest()); const ResourceResponse& redirectResponse( passedRedirectResponse.toResourceResponse()); newRequest.setRedirectStatus( ResourceRequest::RedirectStatus::FollowedRedirect); const KURL originalURL = newRequest.url(); ResourceRequestBlockedReason blockedReason = m_fetcher->willFollowRedirect( m_resource.get(), newRequest, redirectResponse); if (blockedReason != ResourceRequestBlockedReason::None) { cancelForRedirectAccessCheckError(newRequest.url(), blockedReason); return false; } // ResourceFetcher::willFollowRedirect() may rewrite the URL to // something else not for rejecting redirect but for other reasons. // E.g. WebFrameTestClient::willSendRequest() and // RenderFrameImpl::willSendRequest(). We should reflect the // rewriting but currently we cannot. So, return false to make the // redirect fail. if (newRequest.url() != originalURL) { cancelForRedirectAccessCheckError(newRequest.url(), ResourceRequestBlockedReason::Other); return false; } if (!m_resource->willFollowRedirect(newRequest, redirectResponse)) { cancelForRedirectAccessCheckError(newRequest.url(), ResourceRequestBlockedReason::Other); return false; } return true; }
void ResourceLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& response, WebDataConsumerHandle* rawHandle) { ASSERT(!response.isNull()); ASSERT(m_state == Initialized); // |rawHandle|'s ownership is transferred to the callee. OwnPtr<WebDataConsumerHandle> handle = adoptPtr(rawHandle); bool isMultipartPayload = response.isMultipartPayload(); bool isValidStateTransition = (m_connectionState == ConnectionStateStarted || m_connectionState == ConnectionStateReceivedResponse); // In the case of multipart loads, calls to didReceiveData & didReceiveResponse can be interleaved. RELEASE_ASSERT(isMultipartPayload || isValidStateTransition); m_connectionState = ConnectionStateReceivedResponse; const ResourceResponse& resourceResponse = response.toResourceResponse(); if (responseNeedsAccessControlCheck()) { if (response.wasFetchedViaServiceWorker()) { if (response.wasFallbackRequiredByServiceWorker()) { m_loader->cancel(); m_loader.clear(); m_connectionState = ConnectionStateStarted; m_loader = adoptPtr(Platform::current()->createURLLoader()); ASSERT(m_loader); ASSERT(!m_request.skipServiceWorker()); m_request.setSkipServiceWorker(true); WrappedResourceRequest wrappedRequest(m_request); m_loader->loadAsynchronously(wrappedRequest, this); return; } } else { // If the response successfully validated a cached resource, perform // the access control with respect to it. Need to do this right here // before the resource switches clients over to that validated resource. Resource* resource = m_resource; if (!resource->isCacheValidator() || resourceResponse.httpStatusCode() != 304) m_resource->setResponse(resourceResponse); if (!m_fetcher->canAccessResource(resource, m_options.securityOrigin.get(), response.url(), ResourceFetcher::ShouldLogAccessControlErrors)) { m_fetcher->didReceiveResponse(m_resource, resourceResponse); cancel(ResourceError::cancelledDueToAccessCheckError(KURL(response.url()))); return; } } } m_resource->responseReceived(resourceResponse, handle.release()); if (m_state == Terminated) return; m_fetcher->didReceiveResponse(m_resource, resourceResponse); if (m_state == Terminated) return; if (response.toResourceResponse().isMultipart()) { // We only support multipart for images, though the image may be loaded // as a main resource that we end up displaying through an ImageDocument. if (!m_resource->isImage() && m_resource->type() != Resource::MainResource) { cancel(); return; } m_loadingMultipartContent = true; } else if (isMultipartPayload) { // Since a subresource loader does not load multipart sections progressively, data was delivered to the loader all at once. // After the first multipart section is complete, signal to delegates that this load is "finished" m_fetcher->subresourceLoaderFinishedLoadingOnePart(this); didFinishLoadingOnePart(0, WebURLLoaderClient::kUnknownEncodedDataLength); } if (m_state == Terminated) return; if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnoreHTTPStatusCodeErrors()) return; m_state = Finishing; if (!m_notifiedLoadComplete) { m_notifiedLoadComplete = true; m_fetcher->didFailLoading(m_resource, ResourceError::cancelledError(m_request.url())); } ASSERT(m_state != Terminated); m_resource->error(Resource::LoadError); cancel(); }