Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "FetchHeaderList.h" | |
| 7 | |
| 8 #include "core/fetch/CrossOriginAccessControl.h" | |
| 9 #include "core/xml/XMLHttpRequest.h" | |
| 10 #include "platform/network/HTTPParsers.h" | |
| 11 #include "wtf/PassOwnPtr.h" | |
| 12 | |
| 13 namespace WebCore { | |
| 14 | |
| 15 PassRefPtr<FetchHeaderList> FetchHeaderList::create() | |
| 16 { | |
| 17 return adoptRef(new FetchHeaderList()); | |
| 18 } | |
| 19 | |
| 20 PassRefPtr<FetchHeaderList> FetchHeaderList::createCopy() | |
| 21 { | |
| 22 RefPtr<FetchHeaderList> list = adoptRef(new FetchHeaderList()); | |
|
yhirano
2014/06/26 07:22:12
Can you use create?
horo
2014/06/26 08:30:08
deleted.
| |
| 23 for (size_t i = 0; i < m_headerList.size(); ++i) { | |
| 24 list->append(m_headerList[i]->first, m_headerList[i]->second); | |
| 25 } | |
| 26 return list.release(); | |
| 27 } | |
| 28 | |
| 29 FetchHeaderList::FetchHeaderList() | |
| 30 { | |
| 31 } | |
| 32 | |
| 33 FetchHeaderList::~FetchHeaderList() | |
| 34 { | |
| 35 } | |
| 36 | |
| 37 void FetchHeaderList::append(const String& name, const String& value) | |
| 38 { | |
| 39 // To append a name/value (name/value) pair to a header list (list), append | |
| 40 // a new header whose name is name and value is value, to list. | |
| 41 m_headerList.append(adoptPtr(new Header(name, value))); | |
| 42 } | |
| 43 | |
| 44 void FetchHeaderList::set(const String& name, const String& value) | |
| 45 { | |
| 46 // To set a name/value (name/value) pair in a header list (list), run these | |
| 47 // steps: | |
| 48 // 1. If there are any headers in list whose name is name, set the value of | |
| 49 // the first such header to value and remove the others. | |
| 50 // 2. Otherwise, append a new header whose name is name and value is value, | |
| 51 // to list. | |
| 52 for (size_t i = 0; i < m_headerList.size(); ++i) { | |
| 53 if (m_headerList[i]->first == name) { | |
| 54 m_headerList[i]->second = value; | |
| 55 for (size_t j = i + 1; j < m_headerList.size(); ) { | |
| 56 if (m_headerList[j]->first == name) | |
| 57 m_headerList.remove(j); | |
| 58 else | |
| 59 ++j; | |
| 60 } | |
| 61 return; | |
| 62 } | |
| 63 } | |
| 64 m_headerList.append(adoptPtr(new Header(name, value))); | |
| 65 } | |
| 66 | |
| 67 size_t FetchHeaderList::size() const | |
| 68 { | |
| 69 return m_headerList.size(); | |
| 70 } | |
| 71 | |
| 72 void FetchHeaderList::remove(const String& name) | |
| 73 { | |
| 74 for (size_t i = 0; i < m_headerList.size(); ) { | |
| 75 if (m_headerList[i]->first == name) { | |
| 76 m_headerList.remove(i); | |
| 77 } else { | |
| 78 ++i; | |
| 79 } | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 bool FetchHeaderList::get(const String& name, String& result) const | |
| 84 { | |
| 85 for (size_t i = 0; i < m_headerList.size(); ++i) { | |
| 86 if (m_headerList[i]->first == name) { | |
| 87 result = m_headerList[i]->second; | |
| 88 return true; | |
| 89 } | |
| 90 } | |
| 91 return false; | |
| 92 } | |
| 93 | |
| 94 void FetchHeaderList::getAll(const String& name, Vector<String>& result) const | |
| 95 { | |
|
yhirano
2014/06/26 07:22:12
Let's clear |result| here.
horo
2014/06/26 08:30:08
Done.
| |
| 96 for (size_t i = 0; i < m_headerList.size(); ++i) { | |
| 97 if (m_headerList[i]->first == name) | |
| 98 result.append(m_headerList[i]->second); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 bool FetchHeaderList::has(const String& name) const | |
| 103 { | |
| 104 for (size_t i = 0; i < m_headerList.size(); ++i) { | |
| 105 if (m_headerList[i]->first == name) | |
| 106 return true; | |
| 107 } | |
| 108 return false; | |
| 109 } | |
| 110 | |
| 111 void FetchHeaderList::clearList() | |
| 112 { | |
| 113 m_headerList.clear(); | |
| 114 } | |
| 115 | |
| 116 bool FetchHeaderList::containsNonSimpleHeader() const | |
| 117 { | |
| 118 for (size_t i = 0; i < m_headerList.size(); ++i) { | |
| 119 if (!isSimpleHeader(m_headerList[i]->first, m_headerList[i]->second)) | |
| 120 return true; | |
| 121 } | |
| 122 return false; | |
| 123 } | |
| 124 | |
| 125 | |
| 126 bool FetchHeaderList::isValidHeaderName(const String& name) | |
| 127 { | |
| 128 // FIXME: According to the spec (http://fetch.spec.whatwg.org/) should we | |
| 129 // accept all characters in the range 0x00 to 0x7F? | |
| 130 return isValidHTTPToken(name); | |
| 131 } | |
| 132 | |
| 133 bool FetchHeaderList::isValidHeaderValue(const String& value) | |
| 134 { | |
| 135 // A value is a byte sequence that matches the field-value token production | |
| 136 // and contains no 0x0A or 0x0D bytes. | |
| 137 return (value.find('\r') == kNotFound) && (value.find('\n') == kNotFound); | |
| 138 } | |
| 139 | |
| 140 bool FetchHeaderList::isSimpleHeader(const String& name, const String& value) | |
| 141 { | |
| 142 // A simple header is a header whose name is either one of `Accept`, | |
| 143 // `Accept-Language`, and `Content-Language`, or whose name is | |
| 144 // `Content-Type` and value, once parsed, is one of | |
| 145 // `application/x-www-form-urlencoded`, `multipart/form-data`, and | |
| 146 // `text/plain`. | |
| 147 return isOnAccessControlSimpleRequestHeaderWhitelist(AtomicString(name), Ato micString(value)); | |
|
yhirano
2014/06/26 07:22:12
What isOnAccessControlSimpleRequestHeaderWhilelist
horo
2014/06/26 08:30:08
Could you please let me know what is the differenc
yhirano
2014/06/26 08:55:10
"origin" and "referer" are whitelisted in the func
horo
2014/06/26 09:16:52
Oh, I didn't noticed that.
Thank you for pointing
| |
| 148 } | |
| 149 | |
| 150 bool FetchHeaderList::isForbiddenHeaderName(const String& name) | |
| 151 { | |
| 152 // A forbidden header name is a header names that is one of: | |
| 153 // Accept-Charset, Accept-Encoding, Access-Control-Request-Headers, | |
| 154 // Access-Control-Request-Method, Connection, Content-Length, Cookie, | |
| 155 // Cookie2, Date, DNT, Expect, Host, Keep-Alive, Origin, Referer, TE, | |
| 156 // Trailer, Transfer-Encoding, Upgrade, User-Agent, Via | |
| 157 // and a header name that starts with Proxy- or Sec- (including when it is | |
| 158 // just Proxy- or Sec-). | |
| 159 return !XMLHttpRequest::isAllowedHTTPHeader(name); | |
| 160 } | |
| 161 | |
| 162 bool FetchHeaderList::isForbiddenResponseHeaderName(const String& name) | |
| 163 { | |
| 164 // A forbidden response header name is a header name that is one of: | |
| 165 // `Set-Cookie`, `Set-Cookie2` | |
| 166 return equalIgnoringCase(name, "set-cookie") || equalIgnoringCase(name, "set -cookie2"); | |
| 167 } | |
| 168 | |
| 169 } // namespace WebCore | |
| OLD | NEW |