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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "FetchResponseData.h"
7
8 #include "core/fetch/CrossOriginAccessControl.h"
9 #include "modules/serviceworkers/FetchHeaderList.h"
10 #include "public/platform/WebServiceWorkerResponse.h"
11
12 namespace WebCore {
13
14 PassRefPtr<FetchResponseData> FetchResponseData::create()
15 {
16 // "Unless stated otherwise, a response's url is null, status is 200, status
17 // message is `OK`, header list is an empty header list, and body is null."
18 return adoptRef(new FetchResponseData(DefaultType, 200, "OK"));
19 }
20
21 PassRefPtr<FetchResponseData> FetchResponseData::createNetworkErrorResponse()
22 {
23 // "A network error is a response whose status is always 0, status message
24 // is always the empty byte sequence, header list is aways an empty list,
25 // and body is always null."
26 return adoptRef(new FetchResponseData(ErrorType, 0, ""));
27 }
28
29 PassRefPtr<FetchResponseData> FetchResponseData::createBasicFilteredResponse()
30 {
31 // "A basic filtered response is a filtered response whose type is |basic|,
32 // header list excludes any headers in internal response's header list whose
33 // name is `Set-Cookie` or `Set-Cookie2`."
34 RefPtr<FetchResponseData> response = adoptRef(new FetchResponseData(BasicTyp e, m_status, m_statusMessage));
35 response->m_url = m_url;
36 for (size_t i = 0; i < m_headerList->size(); ++i) {
37 const FetchHeaderList::Header* header = m_headerList->list()[i].get();
38 if (header->first == "set-cookie" || header->first == "set-cookie2")
39 continue;
40 response->m_headerList->append(header->first, header->second);
41 }
42 response-> m_blobDataHandle = m_blobDataHandle;
falken 2014/07/07 08:10:40 errant space
horo 2014/07/07 10:19:44 Done.
43 response->m_internalResponse = this;
44 return response.release();
45 }
46
47 PassRefPtr<FetchResponseData> FetchResponseData::createCORSFilteredResponse()
48 {
49 // "A CORS filtered response is a filtered response whose type is |CORS|,
50 // header list excludes all headers in internal response's header list,
51 // except those whose name is either one of `Cache-Control`,
52 // `Content-Language`, `Content-Type`, `Expires`, `Last-Modified`, and
53 // `Pragma`, and except those whose name is one of the values resulting from
54 // parsing `Access-Control-Expose-Headers` in internal response's header
55 // list."
56 RefPtr<FetchResponseData> response = adoptRef(new FetchResponseData(CORSType , m_status, m_statusMessage));
57 response->m_url = m_url;
58 HTTPHeaderSet accessControlExposeHeaderSet;
59 String accessControlExposeHeaders;
60 if (m_headerList->get("access-control-expose-headers", accessControlExposeHe aders)) {
61 parseAccessControlExposeHeadersAllowList(accessControlExposeHeaders, acc essControlExposeHeaderSet);
62 }
63 for (size_t i = 0; i < m_headerList->size(); ++i) {
64 const FetchHeaderList::Header* header = m_headerList->list()[i].get();
65 if (!isOnAccessControlResponseHeaderWhitelist(header->first) && !accessC ontrolExposeHeaderSet.contains(header->first))
66 continue;
67 response->m_headerList->append(header->first, header->second);
68 }
69 response-> m_blobDataHandle = m_blobDataHandle;
falken 2014/07/07 08:10:40 space
horo 2014/07/07 10:19:44 Done.
70 response->m_internalResponse = this;
71 return response.release();
72 }
73
74 PassRefPtr<FetchResponseData> FetchResponseData::createOpaqueFilteredResponse()
75 {
76 // "An opaque filtered response is a filtered response whose type is
77 // |opaque|, status is 0, status message is the empty byte sequence, header
78 // list is an empty list, and body is null."
79 RefPtr<FetchResponseData> response = adoptRef(new FetchResponseData(OpaqueTy pe, 0, ""));
80 response->m_internalResponse = this;
81 return response.release();
82 }
83
84 void FetchResponseData::populateWebServiceWorkerResponse(blink::WebServiceWorker Response& response)
85 {
86 if (m_internalResponse) {
87 m_internalResponse->populateWebServiceWorkerResponse(response);
88 return;
89 }
90 response.setURL(url());
91 response.setStatus(status());
92 response.setStatusText(statusMessage());
93 for (size_t i = 0; i < headerList()->size(); ++i) {
94 const FetchHeaderList::Header* header = headerList()->list()[i].get();
95 response.setHeader(header->first, header->second);
96 }
97 response.setBlobDataHandle(blobDataHandle());
98 }
99
100 FetchResponseData::FetchResponseData(Type type, unsigned short status, AtomicStr ing statusMessage)
101 : m_type(type)
102 , m_status(status)
103 , m_statusMessage(statusMessage)
104 , m_headerList(FetchHeaderList::create())
105 {
106 }
107
108 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698