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 "modules/fetch/Response.h" | 5 #include "modules/fetch/Response.h" |
6 | 6 |
7 #include "bindings/core/v8/Dictionary.h" | 7 #include "bindings/core/v8/Dictionary.h" |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
10 #include "bindings/core/v8/V8ArrayBuffer.h" | 10 #include "bindings/core/v8/V8ArrayBuffer.h" |
11 #include "bindings/core/v8/V8ArrayBufferView.h" | 11 #include "bindings/core/v8/V8ArrayBufferView.h" |
12 #include "bindings/core/v8/V8Binding.h" | 12 #include "bindings/core/v8/V8Binding.h" |
13 #include "bindings/core/v8/V8Blob.h" | 13 #include "bindings/core/v8/V8Blob.h" |
14 #include "bindings/core/v8/V8FormData.h" | 14 #include "bindings/core/v8/V8FormData.h" |
15 #include "bindings/core/v8/V8HiddenValue.h" | 15 #include "bindings/core/v8/V8HiddenValue.h" |
16 #include "bindings/core/v8/V8URLSearchParams.h" | 16 #include "bindings/core/v8/V8URLSearchParams.h" |
17 #include "core/dom/DOMArrayBuffer.h" | 17 #include "core/dom/DOMArrayBuffer.h" |
18 #include "core/dom/DOMArrayBufferView.h" | 18 #include "core/dom/DOMArrayBufferView.h" |
19 #include "core/dom/URLSearchParams.h" | 19 #include "core/dom/URLSearchParams.h" |
20 #include "core/fileapi/Blob.h" | 20 #include "core/fileapi/Blob.h" |
21 #include "core/html/FormData.h" | 21 #include "core/html/FormData.h" |
22 #include "core/streams/ReadableStreamOperations.h" | 22 #include "core/streams/ReadableStreamOperations.h" |
23 #include "modules/fetch/BlobBytesConsumer.h" | 23 #include "modules/fetch/BlobBytesConsumer.h" |
24 #include "modules/fetch/BodyStreamBuffer.h" | 24 #include "modules/fetch/BodyStreamBuffer.h" |
25 #include "modules/fetch/FormDataBytesConsumer.h" | 25 #include "modules/fetch/FormDataBytesConsumer.h" |
26 #include "modules/fetch/ResponseInit.h" | 26 #include "modules/fetch/ResponseInit.h" |
27 #include "platform/network/EncodedFormData.h" | 27 #include "platform/network/EncodedFormData.h" |
28 #include "platform/network/HTTPHeaderMap.h" | 28 #include "platform/network/HTTPHeaderMap.h" |
| 29 #include "platform/network/NetworkUtils.h" |
29 #include "public/platform/modules/serviceworker/WebServiceWorkerResponse.h" | 30 #include "public/platform/modules/serviceworker/WebServiceWorkerResponse.h" |
30 #include "wtf/RefPtr.h" | 31 #include "wtf/RefPtr.h" |
31 #include <memory> | 32 #include <memory> |
32 | 33 |
33 namespace blink { | 34 namespace blink { |
34 | 35 |
35 namespace { | 36 namespace { |
36 | 37 |
37 FetchResponseData* createFetchResponseDataFromWebResponse( | 38 FetchResponseData* createFetchResponseDataFromWebResponse( |
38 ScriptState* scriptState, | 39 ScriptState* scriptState, |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 Response* Response::redirect(ExecutionContext* context, | 306 Response* Response::redirect(ExecutionContext* context, |
306 const String& url, | 307 const String& url, |
307 unsigned short status, | 308 unsigned short status, |
308 ExceptionState& exceptionState) { | 309 ExceptionState& exceptionState) { |
309 KURL parsedURL = context->completeURL(url); | 310 KURL parsedURL = context->completeURL(url); |
310 if (!parsedURL.isValid()) { | 311 if (!parsedURL.isValid()) { |
311 exceptionState.throwTypeError("Failed to parse URL from " + url); | 312 exceptionState.throwTypeError("Failed to parse URL from " + url); |
312 return nullptr; | 313 return nullptr; |
313 } | 314 } |
314 | 315 |
315 if (status != 301 && status != 302 && status != 303 && status != 307 && | 316 if (!NetworkUtils::isRedirectResponseCode(status)) { |
316 status != 308) { | |
317 exceptionState.throwRangeError("Invalid status code"); | 317 exceptionState.throwRangeError("Invalid status code"); |
318 return nullptr; | 318 return nullptr; |
319 } | 319 } |
320 | 320 |
321 Response* r = new Response(context); | 321 Response* r = new Response(context); |
322 r->m_headers->setGuard(Headers::ImmutableGuard); | 322 r->m_headers->setGuard(Headers::ImmutableGuard); |
323 r->m_response->setStatus(status); | 323 r->m_response->setStatus(status); |
324 r->m_response->headerList()->set("Location", parsedURL); | 324 r->m_response->headerList()->set("Location", parsedURL); |
325 | 325 |
326 return r; | 326 return r; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 V8HiddenValue::internalBodyBuffer(scriptState->isolate()), bodyBuffer); | 461 V8HiddenValue::internalBodyBuffer(scriptState->isolate()), bodyBuffer); |
462 } | 462 } |
463 | 463 |
464 DEFINE_TRACE(Response) { | 464 DEFINE_TRACE(Response) { |
465 Body::trace(visitor); | 465 Body::trace(visitor); |
466 visitor->trace(m_response); | 466 visitor->trace(m_response); |
467 visitor->trace(m_headers); | 467 visitor->trace(m_headers); |
468 } | 468 } |
469 | 469 |
470 } // namespace blink | 470 } // namespace blink |
OLD | NEW |