| 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/FetchResponseData.h" | 5 #include "modules/fetch/FetchResponseData.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptState.h" | 7 #include "bindings/core/v8/ScriptState.h" |
| 8 #include "core/dom/DOMArrayBuffer.h" | 8 #include "core/dom/DOMArrayBuffer.h" |
| 9 #include "core/fetch/CrossOriginAccessControl.h" | 9 #include "core/fetch/CrossOriginAccessControl.h" |
| 10 #include "core/fetch/FetchUtils.h" | 10 #include "core/fetch/FetchUtils.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 return new FetchResponseData(ErrorType, 0, ""); | 60 return new FetchResponseData(ErrorType, 0, ""); |
| 61 } | 61 } |
| 62 | 62 |
| 63 FetchResponseData* FetchResponseData::createWithBuffer(BodyStreamBuffer* buffer) | 63 FetchResponseData* FetchResponseData::createWithBuffer(BodyStreamBuffer* buffer) |
| 64 { | 64 { |
| 65 FetchResponseData* response = FetchResponseData::create(); | 65 FetchResponseData* response = FetchResponseData::create(); |
| 66 response->m_buffer = buffer; | 66 response->m_buffer = buffer; |
| 67 return response; | 67 return response; |
| 68 } | 68 } |
| 69 | 69 |
| 70 FetchResponseData* FetchResponseData::createBasicFilteredResponse() | 70 FetchResponseData* FetchResponseData::createBasicFilteredResponse() const |
| 71 { | 71 { |
| 72 DCHECK_EQ(m_type, DefaultType); |
| 72 // "A basic filtered response is a filtered response whose type is |basic|, | 73 // "A basic filtered response is a filtered response whose type is |basic|, |
| 73 // header list excludes any headers in internal response's header list whose | 74 // header list excludes any headers in internal response's header list whose |
| 74 // name is `Set-Cookie` or `Set-Cookie2`." | 75 // name is `Set-Cookie` or `Set-Cookie2`." |
| 75 FetchResponseData* response = new FetchResponseData(BasicType, m_status, m_s
tatusMessage); | 76 FetchResponseData* response = new FetchResponseData(BasicType, m_status, m_s
tatusMessage); |
| 76 response->m_url = m_url; | 77 response->m_url = m_url; |
| 77 for (size_t i = 0; i < m_headerList->size(); ++i) { | 78 for (size_t i = 0; i < m_headerList->size(); ++i) { |
| 78 const FetchHeaderList::Header* header = m_headerList->list()[i].get(); | 79 const FetchHeaderList::Header* header = m_headerList->list()[i].get(); |
| 79 if (FetchUtils::isForbiddenResponseHeaderName(header->first)) | 80 if (FetchUtils::isForbiddenResponseHeaderName(header->first)) |
| 80 continue; | 81 continue; |
| 81 response->m_headerList->append(header->first, header->second); | 82 response->m_headerList->append(header->first, header->second); |
| 82 } | 83 } |
| 83 response->m_buffer = m_buffer; | 84 response->m_buffer = m_buffer; |
| 84 response->m_mimeType = m_mimeType; | 85 response->m_mimeType = m_mimeType; |
| 85 response->m_internalResponse = this; | 86 response->m_internalResponse = const_cast<FetchResponseData*>(this); |
| 86 return response; | 87 return response; |
| 87 } | 88 } |
| 88 | 89 |
| 89 FetchResponseData* FetchResponseData::createCORSFilteredResponse() | 90 FetchResponseData* FetchResponseData::createCORSFilteredResponse() const |
| 90 { | 91 { |
| 92 DCHECK_EQ(m_type, DefaultType); |
| 91 // "A CORS filtered response is a filtered response whose type is |CORS|, | 93 // "A CORS filtered response is a filtered response whose type is |CORS|, |
| 92 // header list excludes all headers in internal response's header list, | 94 // header list excludes all headers in internal response's header list, |
| 93 // except those whose name is either one of `Cache-Control`, | 95 // except those whose name is either one of `Cache-Control`, |
| 94 // `Content-Language`, `Content-Type`, `Expires`, `Last-Modified`, and | 96 // `Content-Language`, `Content-Type`, `Expires`, `Last-Modified`, and |
| 95 // `Pragma`, and except those whose name is one of the values resulting from | 97 // `Pragma`, and except those whose name is one of the values resulting from |
| 96 // parsing `Access-Control-Expose-Headers` in internal response's header | 98 // parsing `Access-Control-Expose-Headers` in internal response's header |
| 97 // list." | 99 // list." |
| 98 FetchResponseData* response = new FetchResponseData(CORSType, m_status, m_st
atusMessage); | 100 FetchResponseData* response = new FetchResponseData(CORSType, m_status, m_st
atusMessage); |
| 99 response->m_url = m_url; | 101 response->m_url = m_url; |
| 100 HTTPHeaderSet accessControlExposeHeaderSet; | 102 HTTPHeaderSet accessControlExposeHeaderSet; |
| 101 String accessControlExposeHeaders; | 103 String accessControlExposeHeaders; |
| 102 if (m_headerList->get("access-control-expose-headers", accessControlExposeHe
aders)) | 104 if (m_headerList->get("access-control-expose-headers", accessControlExposeHe
aders)) |
| 103 parseAccessControlExposeHeadersAllowList(accessControlExposeHeaders, acc
essControlExposeHeaderSet); | 105 parseAccessControlExposeHeadersAllowList(accessControlExposeHeaders, acc
essControlExposeHeaderSet); |
| 104 for (size_t i = 0; i < m_headerList->size(); ++i) { | 106 for (size_t i = 0; i < m_headerList->size(); ++i) { |
| 105 const FetchHeaderList::Header* header = m_headerList->list()[i].get(); | 107 const FetchHeaderList::Header* header = m_headerList->list()[i].get(); |
| 106 const String& name = header->first; | 108 const String& name = header->first; |
| 107 if (isOnAccessControlResponseHeaderWhitelist(name) || (accessControlExpo
seHeaderSet.contains(name) && !FetchUtils::isForbiddenResponseHeaderName(name))) | 109 if (isOnAccessControlResponseHeaderWhitelist(name) || (accessControlExpo
seHeaderSet.contains(name) && !FetchUtils::isForbiddenResponseHeaderName(name))) |
| 108 response->m_headerList->append(name, header->second); | 110 response->m_headerList->append(name, header->second); |
| 109 } | 111 } |
| 110 response->m_buffer = m_buffer; | 112 response->m_buffer = m_buffer; |
| 111 response->m_mimeType = m_mimeType; | 113 response->m_mimeType = m_mimeType; |
| 112 response->m_internalResponse = this; | 114 response->m_internalResponse = const_cast<FetchResponseData*>(this); |
| 113 return response; | 115 return response; |
| 114 } | 116 } |
| 115 | 117 |
| 116 FetchResponseData* FetchResponseData::createOpaqueFilteredResponse() | 118 FetchResponseData* FetchResponseData::createOpaqueFilteredResponse() const |
| 117 { | 119 { |
| 120 DCHECK_EQ(m_type, DefaultType); |
| 118 // "An opaque filtered response is a filtered response whose type is | 121 // "An opaque filtered response is a filtered response whose type is |
| 119 // 'opaque', url list is the empty list, status is 0, status message is the | 122 // 'opaque', url list is the empty list, status is 0, status message is the |
| 120 // empty byte sequence, header list is the empty list, body is null, and | 123 // empty byte sequence, header list is the empty list, body is null, and |
| 121 // cache state is 'none'." | 124 // cache state is 'none'." |
| 122 // | 125 // |
| 123 // https://fetch.spec.whatwg.org/#concept-filtered-response-opaque | 126 // https://fetch.spec.whatwg.org/#concept-filtered-response-opaque |
| 124 FetchResponseData* response = new FetchResponseData(OpaqueType, 0, ""); | 127 FetchResponseData* response = new FetchResponseData(OpaqueType, 0, ""); |
| 125 response->m_internalResponse = this; | 128 response->m_internalResponse = const_cast<FetchResponseData*>(this); |
| 126 return response; | 129 return response; |
| 127 } | 130 } |
| 128 | 131 |
| 129 FetchResponseData* FetchResponseData::createOpaqueRedirectFilteredResponse() | 132 FetchResponseData* FetchResponseData::createOpaqueRedirectFilteredResponse() con
st |
| 130 { | 133 { |
| 134 DCHECK_EQ(m_type, DefaultType); |
| 131 // "An opaque filtered response is a filtered response whose type is | 135 // "An opaque filtered response is a filtered response whose type is |
| 132 // 'opaqueredirect', status is 0, status message is the empty byte sequence, | 136 // 'opaqueredirect', status is 0, status message is the empty byte sequence, |
| 133 // header list is the empty list, body is null, and cache state is 'none'." | 137 // header list is the empty list, body is null, and cache state is 'none'." |
| 134 // | 138 // |
| 135 // https://fetch.spec.whatwg.org/#concept-filtered-response-opaque-redirect | 139 // https://fetch.spec.whatwg.org/#concept-filtered-response-opaque-redirect |
| 136 FetchResponseData* response = new FetchResponseData(OpaqueRedirectType, 0, "
"); | 140 FetchResponseData* response = new FetchResponseData(OpaqueRedirectType, 0, "
"); |
| 137 response->m_url = m_url; | 141 response->m_url = m_url; |
| 138 response->m_internalResponse = this; | 142 response->m_internalResponse = const_cast<FetchResponseData*>(this); |
| 139 return response; | 143 return response; |
| 140 } | 144 } |
| 141 | 145 |
| 142 String FetchResponseData::mimeType() const | 146 String FetchResponseData::mimeType() const |
| 143 { | 147 { |
| 144 return m_mimeType; | 148 return m_mimeType; |
| 145 } | 149 } |
| 146 | 150 |
| 147 BodyStreamBuffer* FetchResponseData::internalBuffer() const | 151 BodyStreamBuffer* FetchResponseData::internalBuffer() const |
| 148 { | 152 { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 } | 258 } |
| 255 | 259 |
| 256 DEFINE_TRACE(FetchResponseData) | 260 DEFINE_TRACE(FetchResponseData) |
| 257 { | 261 { |
| 258 visitor->trace(m_headerList); | 262 visitor->trace(m_headerList); |
| 259 visitor->trace(m_internalResponse); | 263 visitor->trace(m_internalResponse); |
| 260 visitor->trace(m_buffer); | 264 visitor->trace(m_buffer); |
| 261 } | 265 } |
| 262 | 266 |
| 263 } // namespace blink | 267 } // namespace blink |
| OLD | NEW |