| 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 "modules/fetch/BodyStreamBuffer.h" | 9 #include "modules/fetch/BodyStreamBuffer.h" |
| 10 #include "modules/fetch/FetchHeaderList.h" | 10 #include "modules/fetch/FetchHeaderList.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 75 } |
| 76 | 76 |
| 77 FetchResponseData* FetchResponseData::createBasicFilteredResponse() const { | 77 FetchResponseData* FetchResponseData::createBasicFilteredResponse() const { |
| 78 DCHECK_EQ(m_type, DefaultType); | 78 DCHECK_EQ(m_type, DefaultType); |
| 79 // "A basic filtered response is a filtered response whose type is |basic|, | 79 // "A basic filtered response is a filtered response whose type is |basic|, |
| 80 // header list excludes any headers in internal response's header list whose | 80 // header list excludes any headers in internal response's header list whose |
| 81 // name is `Set-Cookie` or `Set-Cookie2`." | 81 // name is `Set-Cookie` or `Set-Cookie2`." |
| 82 FetchResponseData* response = | 82 FetchResponseData* response = |
| 83 new FetchResponseData(BasicType, m_status, m_statusMessage); | 83 new FetchResponseData(BasicType, m_status, m_statusMessage); |
| 84 response->setURLList(m_urlList); | 84 response->setURLList(m_urlList); |
| 85 for (size_t i = 0; i < m_headerList->size(); ++i) { | 85 for (const auto& header : m_headerList->list()) { |
| 86 const FetchHeaderList::Header* header = m_headerList->list()[i].get(); | 86 if (FetchUtils::isForbiddenResponseHeaderName(header.first)) |
| 87 if (FetchUtils::isForbiddenResponseHeaderName(header->first)) | |
| 88 continue; | 87 continue; |
| 89 response->m_headerList->append(header->first, header->second); | 88 response->m_headerList->append(header.first, header.second); |
| 90 } | 89 } |
| 91 response->m_buffer = m_buffer; | 90 response->m_buffer = m_buffer; |
| 92 response->m_mimeType = m_mimeType; | 91 response->m_mimeType = m_mimeType; |
| 93 response->m_internalResponse = const_cast<FetchResponseData*>(this); | 92 response->m_internalResponse = const_cast<FetchResponseData*>(this); |
| 94 return response; | 93 return response; |
| 95 } | 94 } |
| 96 | 95 |
| 97 FetchResponseData* FetchResponseData::createCORSFilteredResponse() const { | 96 FetchResponseData* FetchResponseData::createCORSFilteredResponse() const { |
| 98 DCHECK_EQ(m_type, DefaultType); | 97 DCHECK_EQ(m_type, DefaultType); |
| 99 HTTPHeaderSet accessControlExposeHeaderSet; | 98 HTTPHeaderSet accessControlExposeHeaderSet; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 111 // "A CORS filtered response is a filtered response whose type is |CORS|, | 110 // "A CORS filtered response is a filtered response whose type is |CORS|, |
| 112 // header list excludes all headers in internal response's header list, | 111 // header list excludes all headers in internal response's header list, |
| 113 // except those whose name is either one of `Cache-Control`, | 112 // except those whose name is either one of `Cache-Control`, |
| 114 // `Content-Language`, `Content-Type`, `Expires`, `Last-Modified`, and | 113 // `Content-Language`, `Content-Type`, `Expires`, `Last-Modified`, and |
| 115 // `Pragma`, and except those whose name is one of the values resulting from | 114 // `Pragma`, and except those whose name is one of the values resulting from |
| 116 // parsing `Access-Control-Expose-Headers` in internal response's header | 115 // parsing `Access-Control-Expose-Headers` in internal response's header |
| 117 // list." | 116 // list." |
| 118 FetchResponseData* response = | 117 FetchResponseData* response = |
| 119 new FetchResponseData(CORSType, m_status, m_statusMessage); | 118 new FetchResponseData(CORSType, m_status, m_statusMessage); |
| 120 response->setURLList(m_urlList); | 119 response->setURLList(m_urlList); |
| 121 for (size_t i = 0; i < m_headerList->size(); ++i) { | 120 for (const auto& header : m_headerList->list()) { |
| 122 const FetchHeaderList::Header* header = m_headerList->list()[i].get(); | 121 const String& name = header.first; |
| 123 const String& name = header->first; | |
| 124 const bool explicitlyExposed = exposedHeaders.contains(name); | 122 const bool explicitlyExposed = exposedHeaders.contains(name); |
| 125 if (isOnAccessControlResponseHeaderWhitelist(name) || | 123 if (isOnAccessControlResponseHeaderWhitelist(name) || |
| 126 (explicitlyExposed && | 124 (explicitlyExposed && |
| 127 !FetchUtils::isForbiddenResponseHeaderName(name))) { | 125 !FetchUtils::isForbiddenResponseHeaderName(name))) { |
| 128 if (explicitlyExposed) | 126 if (explicitlyExposed) |
| 129 response->m_corsExposedHeaderNames.insert(name); | 127 response->m_corsExposedHeaderNames.insert(name); |
| 130 response->m_headerList->append(name, header->second); | 128 response->m_headerList->append(name, header.second); |
| 131 } | 129 } |
| 132 } | 130 } |
| 133 response->m_buffer = m_buffer; | 131 response->m_buffer = m_buffer; |
| 134 response->m_mimeType = m_mimeType; | 132 response->m_mimeType = m_mimeType; |
| 135 response->m_internalResponse = const_cast<FetchResponseData*>(this); | 133 response->m_internalResponse = const_cast<FetchResponseData*>(this); |
| 136 return response; | 134 return response; |
| 137 } | 135 } |
| 138 | 136 |
| 139 FetchResponseData* FetchResponseData::createOpaqueFilteredResponse() const { | 137 FetchResponseData* FetchResponseData::createOpaqueFilteredResponse() const { |
| 140 DCHECK_EQ(m_type, DefaultType); | 138 DCHECK_EQ(m_type, DefaultType); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 return; | 261 return; |
| 264 } | 262 } |
| 265 response.setURLList(m_urlList); | 263 response.setURLList(m_urlList); |
| 266 response.setStatus(status()); | 264 response.setStatus(status()); |
| 267 response.setStatusText(statusMessage()); | 265 response.setStatusText(statusMessage()); |
| 268 response.setResponseType(fetchTypeToWebType(m_type)); | 266 response.setResponseType(fetchTypeToWebType(m_type)); |
| 269 response.setResponseTime(responseTime()); | 267 response.setResponseTime(responseTime()); |
| 270 response.setCacheStorageCacheName(cacheStorageCacheName()); | 268 response.setCacheStorageCacheName(cacheStorageCacheName()); |
| 271 response.setCorsExposedHeaderNames( | 269 response.setCorsExposedHeaderNames( |
| 272 headerSetToWebVector(m_corsExposedHeaderNames)); | 270 headerSetToWebVector(m_corsExposedHeaderNames)); |
| 273 for (size_t i = 0; i < headerList()->size(); ++i) { | 271 for (const auto& header : headerList()->list()) { |
| 274 const FetchHeaderList::Header* header = headerList()->list()[i].get(); | 272 response.appendHeader(header.first, header.second); |
| 275 response.appendHeader(header->first, header->second); | |
| 276 } | 273 } |
| 277 } | 274 } |
| 278 | 275 |
| 279 FetchResponseData::FetchResponseData(Type type, | 276 FetchResponseData::FetchResponseData(Type type, |
| 280 unsigned short status, | 277 unsigned short status, |
| 281 AtomicString statusMessage) | 278 AtomicString statusMessage) |
| 282 : m_type(type), | 279 : m_type(type), |
| 283 m_status(status), | 280 m_status(status), |
| 284 m_statusMessage(statusMessage), | 281 m_statusMessage(statusMessage), |
| 285 m_headerList(FetchHeaderList::create()), | 282 m_headerList(FetchHeaderList::create()), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 296 } | 293 } |
| 297 } | 294 } |
| 298 | 295 |
| 299 DEFINE_TRACE(FetchResponseData) { | 296 DEFINE_TRACE(FetchResponseData) { |
| 300 visitor->trace(m_headerList); | 297 visitor->trace(m_headerList); |
| 301 visitor->trace(m_internalResponse); | 298 visitor->trace(m_internalResponse); |
| 302 visitor->trace(m_buffer); | 299 visitor->trace(m_buffer); |
| 303 } | 300 } |
| 304 | 301 |
| 305 } // namespace blink | 302 } // namespace blink |
| OLD | NEW |