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

Side by Side Diff: Source/modules/fetch/Response.cpp

Issue 1098473003: Implement redirect() API for Fetch Response (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "modules/fetch/Response.h" 6 #include "modules/fetch/Response.h"
7 7
8 #include "bindings/core/v8/Dictionary.h" 8 #include "bindings/core/v8/Dictionary.h"
9 #include "bindings/core/v8/ExceptionState.h" 9 #include "bindings/core/v8/ExceptionState.h"
10 #include "core/dom/DOMArrayBuffer.h" 10 #include "core/dom/DOMArrayBuffer.h"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 236
237 Response* Response::error(ExecutionContext* context) 237 Response* Response::error(ExecutionContext* context)
238 { 238 {
239 FetchResponseData* responseData = FetchResponseData::createNetworkErrorRespo nse(); 239 FetchResponseData* responseData = FetchResponseData::createNetworkErrorRespo nse();
240 Response* r = new Response(context, responseData); 240 Response* r = new Response(context, responseData);
241 r->m_headers->setGuard(Headers::ImmutableGuard); 241 r->m_headers->setGuard(Headers::ImmutableGuard);
242 r->suspendIfNeeded(); 242 r->suspendIfNeeded();
243 return r; 243 return r;
244 } 244 }
245 245
246 Response* Response::redirect(ExecutionContext* context, const String& url, unsig ned short status, ExceptionState& exceptionState)
247 {
248 KURL parsedURL = context->completeURL(url);
249 if (!parsedURL.isValid()) {
250 exceptionState.throwTypeError("Failed to parse URL from " + url);
251 return nullptr;
252 }
253
254 if (status != 301 && status != 302 && status != 303 && status != 307 && stat us != 308) {
255 exceptionState.throwRangeError("Invalid status code");
256 return nullptr;
257 }
258
259 Response* r = new Response(context);
260 r->suspendIfNeeded();
261 r->m_headers->setGuard(Headers::ImmutableGuard);
262 r->m_response->setStatus(status);
263 r->m_response->headerList()->set("Location", parsedURL);
264
265 return r;
266 }
267
246 String Response::type() const 268 String Response::type() const
247 { 269 {
248 // "The type attribute's getter must return response's type." 270 // "The type attribute's getter must return response's type."
249 switch (m_response->type()) { 271 switch (m_response->type()) {
250 case FetchResponseData::BasicType: 272 case FetchResponseData::BasicType:
251 return "basic"; 273 return "basic";
252 case FetchResponseData::CORSType: 274 case FetchResponseData::CORSType:
253 return "cors"; 275 return "cors";
254 case FetchResponseData::DefaultType: 276 case FetchResponseData::DefaultType:
255 return "default"; 277 return "default";
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 } 418 }
397 419
398 DEFINE_TRACE(Response) 420 DEFINE_TRACE(Response)
399 { 421 {
400 Body::trace(visitor); 422 Body::trace(visitor);
401 visitor->trace(m_response); 423 visitor->trace(m_response);
402 visitor->trace(m_headers); 424 visitor->trace(m_headers);
403 } 425 }
404 426
405 } // namespace blink 427 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698