Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2369)

Unified Diff: Source/modules/serviceworkers/FetchResponseData.cpp

Issue 373613004: [ServiceWorker] Make Response class better conformance with the spec. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/serviceworkers/FetchResponseData.h ('k') | Source/modules/serviceworkers/HeaderMap.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/serviceworkers/FetchResponseData.cpp
diff --git a/Source/modules/serviceworkers/FetchResponseData.cpp b/Source/modules/serviceworkers/FetchResponseData.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..bf0c36cdf7cf4cc64aad9ff65ee974bc9311dd5f
--- /dev/null
+++ b/Source/modules/serviceworkers/FetchResponseData.cpp
@@ -0,0 +1,107 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "FetchResponseData.h"
+
+#include "core/fetch/CrossOriginAccessControl.h"
+#include "modules/serviceworkers/FetchHeaderList.h"
+#include "public/platform/WebServiceWorkerResponse.h"
+
+namespace WebCore {
+
+PassRefPtr<FetchResponseData> FetchResponseData::create()
+{
+ // "Unless stated otherwise, a response's url is null, status is 200, status
+ // message is `OK`, header list is an empty header list, and body is null."
+ return adoptRef(new FetchResponseData(DefaultType, 200, "OK"));
+}
+
+PassRefPtr<FetchResponseData> FetchResponseData::createNetworkErrorResponse()
+{
+ // "A network error is a response whose status is always 0, status message
+ // is always the empty byte sequence, header list is aways an empty list,
+ // and body is always null."
+ return adoptRef(new FetchResponseData(ErrorType, 0, ""));
+}
+
+PassRefPtr<FetchResponseData> FetchResponseData::createBasicFilteredResponse()
+{
+ // "A basic filtered response is a filtered response whose type is |basic|,
+ // header list excludes any headers in internal response's header list whose
+ // name is `Set-Cookie` or `Set-Cookie2`."
+ RefPtr<FetchResponseData> response = adoptRef(new FetchResponseData(BasicType, m_status, m_statusMessage));
+ response->m_url = m_url;
+ for (size_t i = 0; i < m_headerList->size(); ++i) {
+ const FetchHeaderList::Header* header = m_headerList->list()[i].get();
+ if (header->first == "set-cookie" || header->first == "set-cookie2")
+ continue;
+ response->m_headerList->append(header->first, header->second);
+ }
+ response->m_blobDataHandle = m_blobDataHandle;
+ response->m_internalResponse = this;
+ return response.release();
+}
+
+PassRefPtr<FetchResponseData> FetchResponseData::createCORSFilteredResponse()
+{
+ // "A CORS filtered response is a filtered response whose type is |CORS|,
+ // header list excludes all headers in internal response's header list,
+ // except those whose name is either one of `Cache-Control`,
+ // `Content-Language`, `Content-Type`, `Expires`, `Last-Modified`, and
+ // `Pragma`, and except those whose name is one of the values resulting from
+ // parsing `Access-Control-Expose-Headers` in internal response's header
+ // list."
+ RefPtr<FetchResponseData> response = adoptRef(new FetchResponseData(CORSType, m_status, m_statusMessage));
+ response->m_url = m_url;
+ HTTPHeaderSet accessControlExposeHeaderSet;
+ String accessControlExposeHeaders;
+ if (m_headerList->get("access-control-expose-headers", accessControlExposeHeaders))
+ parseAccessControlExposeHeadersAllowList(accessControlExposeHeaders, accessControlExposeHeaderSet);
+ for (size_t i = 0; i < m_headerList->size(); ++i) {
+ const FetchHeaderList::Header* header = m_headerList->list()[i].get();
+ if (!isOnAccessControlResponseHeaderWhitelist(header->first) && !accessControlExposeHeaderSet.contains(header->first))
+ continue;
+ response->m_headerList->append(header->first, header->second);
+ }
+ response->m_blobDataHandle = m_blobDataHandle;
+ response->m_internalResponse = this;
+ return response.release();
+}
+
+PassRefPtr<FetchResponseData> FetchResponseData::createOpaqueFilteredResponse()
+{
+ // "An opaque filtered response is a filtered response whose type is
+ // |opaque|, status is 0, status message is the empty byte sequence, header
+ // list is an empty list, and body is null."
+ RefPtr<FetchResponseData> response = adoptRef(new FetchResponseData(OpaqueType, 0, ""));
+ response->m_internalResponse = this;
+ return response.release();
+}
+
+void FetchResponseData::populateWebServiceWorkerResponse(blink::WebServiceWorkerResponse& response)
+{
+ if (m_internalResponse) {
+ m_internalResponse->populateWebServiceWorkerResponse(response);
+ return;
+ }
+ response.setURL(url());
+ response.setStatus(status());
+ response.setStatusText(statusMessage());
+ for (size_t i = 0; i < headerList()->size(); ++i) {
+ const FetchHeaderList::Header* header = headerList()->list()[i].get();
+ response.setHeader(header->first, header->second);
+ }
+ response.setBlobDataHandle(blobDataHandle());
+}
+
+FetchResponseData::FetchResponseData(Type type, unsigned short status, AtomicString statusMessage)
+ : m_type(type)
+ , m_status(status)
+ , m_statusMessage(statusMessage)
+ , m_headerList(FetchHeaderList::create())
+{
+}
+
+} // namespace WebCore
« no previous file with comments | « Source/modules/serviceworkers/FetchResponseData.h ('k') | Source/modules/serviceworkers/HeaderMap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698