OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |