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

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, 8 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 235
236 Response* Response::error(ExecutionContext* context) 236 Response* Response::error(ExecutionContext* context)
237 { 237 {
238 FetchResponseData* responseData = FetchResponseData::createNetworkErrorRespo nse(); 238 FetchResponseData* responseData = FetchResponseData::createNetworkErrorRespo nse();
239 Response* r = new Response(context, responseData); 239 Response* r = new Response(context, responseData);
240 r->m_headers->setGuard(Headers::ImmutableGuard); 240 r->m_headers->setGuard(Headers::ImmutableGuard);
241 r->suspendIfNeeded(); 241 r->suspendIfNeeded();
242 return r; 242 return r;
243 } 243 }
244 244
245 Response* Response::redirect(ExecutionContext* context, const String& url, unsig ned short status, ExceptionState& exceptionState)
246 {
247 KURL parsedURL = context->completeURL(url);
248 if (!parsedURL.isValid()) {
249 exceptionState.throwTypeError("Failed to parse URL from " + url);
250 return nullptr;
251 }
252
253 if (status !=301 && status !=302 && status !=303 && status !=307 && status ! =308) {
tyoshino (SeeGerritForStatus) 2015/04/20 04:31:44 put a space between != and the second operand
horo 2015/04/20 04:32:12 spaces after "!=" if (status != 301 && status !=
shiva.jm 2015/04/27 10:50:55 Done.
shiva.jm 2015/04/27 10:50:55 Done.
254 exceptionState.throwRangeError("Invalid statusCode");
tyoshino (SeeGerritForStatus) 2015/04/20 04:50:00 statusCode -> status, since the argument name in t
shiva.jm 2015/04/27 10:50:55 Done. changed to "status code"
255 return nullptr;
256 }
257
258 Response* r = new Response(context);
259 r->m_headers->setGuard(Headers::ImmutableGuard);
260 r->suspendIfNeeded();
yhirano 2015/04/20 04:55:30 Please call |suspendIfNeeded| right after creation
shiva.jm 2015/04/27 10:50:55 Done.
261 r->m_response->setStatus(status);
262 r->m_response->headerList()->set("Location", parsedURL);
263
264 return r;
265 }
266
245 String Response::type() const 267 String Response::type() const
246 { 268 {
247 // "The type attribute's getter must return response's type." 269 // "The type attribute's getter must return response's type."
248 switch (m_response->type()) { 270 switch (m_response->type()) {
249 case FetchResponseData::BasicType: 271 case FetchResponseData::BasicType:
250 return "basic"; 272 return "basic";
251 case FetchResponseData::CORSType: 273 case FetchResponseData::CORSType:
252 return "cors"; 274 return "cors";
253 case FetchResponseData::DefaultType: 275 case FetchResponseData::DefaultType:
254 return "default"; 276 return "default";
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 } 402 }
381 403
382 DEFINE_TRACE(Response) 404 DEFINE_TRACE(Response)
383 { 405 {
384 Body::trace(visitor); 406 Body::trace(visitor);
385 visitor->trace(m_response); 407 visitor->trace(m_response);
386 visitor->trace(m_headers); 408 visitor->trace(m_headers);
387 } 409 }
388 410
389 } // namespace blink 411 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698