Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Unified Diff: Source/modules/fetch/FetchManager.cpp

Issue 1280733002: [3/3 blink] Support redirect option of Request and "opaqueredirect" response type. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@Redirect1
Patch Set: rebase Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/modules/fetch/FetchManager.cpp
diff --git a/Source/modules/fetch/FetchManager.cpp b/Source/modules/fetch/FetchManager.cpp
index 989297dbe59509b104bd2b9edd2ab7dba3c3915e..7182b9015309016347900388bde500540aa092fa 100644
--- a/Source/modules/fetch/FetchManager.cpp
+++ b/Source/modules/fetch/FetchManager.cpp
@@ -37,15 +37,6 @@
namespace blink {
-namespace {
-
-bool IsRedirectStatusCode(int statusCode)
-{
- return (statusCode == 301 || statusCode == 302 || statusCode == 303 || statusCode == 307 || statusCode == 308);
-}
-
-} // namespace
-
class FetchManager::Loader final : public NoBaseWillBeGarbageCollectedFinalized<FetchManager::Loader>, public ThreadableLoaderClient, public ContextLifecycleObserver {
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(FetchManager::Loader);
public:
@@ -111,8 +102,6 @@ DEFINE_TRACE(FetchManager::Loader)
void FetchManager::Loader::didReceiveResponse(unsigned long, const ResourceResponse& response, PassOwnPtr<WebDataConsumerHandle> handle)
{
- ASSERT(handle);
-
m_responseHttpStatusCode = response.httpStatusCode();
yhirano 2015/08/18 07:56:49 Please keep the assertion.
horo 2015/08/19 07:36:12 Done.
// Recompute the tainting if the request was redirected to a different
@@ -131,7 +120,16 @@ void FetchManager::Loader::didReceiveResponse(unsigned long, const ResourceRespo
break;
}
}
- FetchResponseData* responseData = FetchResponseData::createWithBuffer(new BodyStreamBuffer(createFetchDataConsumerHandleFromWebHandle(handle)));
+
+ bool isRedirectResponse = false;
+ FetchResponseData* responseData = nullptr;
+ if (!handle) {
+ ASSERT(m_request->redirect() == WebURLRequest::FetchRedirectModeManual);
+ isRedirectResponse = true;
+ responseData = FetchResponseData::create();
+ } else {
+ responseData = FetchResponseData::createWithBuffer(new BodyStreamBuffer(createFetchDataConsumerHandleFromWebHandle(handle)));
+ }
responseData->setStatus(response.httpStatusCode());
responseData->setStatusMessage(response.httpStatusText());
for (auto& it : response.httpHeaderFields())
@@ -141,26 +139,9 @@ void FetchManager::Loader::didReceiveResponse(unsigned long, const ResourceRespo
FetchResponseData* taintedResponse = nullptr;
- if (IsRedirectStatusCode(m_responseHttpStatusCode)) {
- Vector<String> locations;
- responseData->headerList()->getAll("location", locations);
- if (locations.size() > 1) {
- performNetworkError("Multiple Location header.");
- return;
- }
- if (locations.size() == 1) {
- KURL locationURL(m_request->url(), locations[0]);
- if (!locationURL.isValid()) {
- performNetworkError("Invalid Location header.");
- return;
- }
- ASSERT(m_request->redirect() == WebURLRequest::FetchRedirectModeManual);
- taintedResponse = responseData->createOpaqueRedirectFilteredResponse();
- }
- // When the location header doesn't exist, we don't treat the response
- // as a redirect response, and execute tainting.
- }
- if (!taintedResponse) {
+ if (isRedirectResponse) {
+ taintedResponse = responseData->createOpaqueRedirectFilteredResponse();
+ } else {
switch (m_request->tainting()) {
case FetchRequestData::BasicTainting:
taintedResponse = responseData->createBasicFilteredResponse();
@@ -177,6 +158,16 @@ void FetchManager::Loader::didReceiveResponse(unsigned long, const ResourceRespo
r->headers()->setGuard(Headers::ImmutableGuard);
m_resolver->resolve(r);
m_resolver.clear();
+
+ if (isRedirectResponse) {
+ // There is no need to read the body of redirect response because there
+ // is no way to read the body of opaque-redirect filtered response's
+ // internal response.
+ // TODO(horo): If we support any API which expose the internal body, we
+ // will have to read the body. And also HTTPCache changes will be needed
+ // because it doesn't store the body of redirect responses.
+ notifyFinished();
+ }
}
void FetchManager::Loader::didFinishLoading(unsigned long, double)

Powered by Google App Engine
This is Rietveld 408576698