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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 && stat
us != 308) { |
| 254 exceptionState.throwRangeError("Invalid status code"); |
| 255 return nullptr; |
| 256 } |
| 257 |
| 258 Response* r = new Response(context); |
| 259 r->suspendIfNeeded(); |
| 260 r->m_headers->setGuard(Headers::ImmutableGuard); |
| 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 Loading... |
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 |
OLD | NEW |