| 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/FetchHeaderList.h" | 5 #include "modules/fetch/FetchHeaderList.h" |
| 6 | 6 |
| 7 #include "core/fetch/FetchUtils.h" | 7 #include "core/fetch/FetchUtils.h" |
| 8 #include "platform/network/HTTPParsers.h" | 8 #include "platform/network/HTTPParsers.h" |
| 9 #include "wtf/PtrUtil.h" | 9 #include "wtf/PtrUtil.h" |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 } | 23 } |
| 24 | 24 |
| 25 FetchHeaderList::FetchHeaderList() {} | 25 FetchHeaderList::FetchHeaderList() {} |
| 26 | 26 |
| 27 FetchHeaderList::~FetchHeaderList() {} | 27 FetchHeaderList::~FetchHeaderList() {} |
| 28 | 28 |
| 29 void FetchHeaderList::append(const String& name, const String& value) { | 29 void FetchHeaderList::append(const String& name, const String& value) { |
| 30 // "To append a name/value (|name|/|value|) pair to a header list (|list|), | 30 // "To append a name/value (|name|/|value|) pair to a header list (|list|), |
| 31 // append a new header whose name is |name|, byte lowercased, and value is | 31 // append a new header whose name is |name|, byte lowercased, and value is |
| 32 // |value|, to |list|." | 32 // |value|, to |list|." |
| 33 m_headerList.append(wrapUnique(new Header(name.lower(), value))); | 33 m_headerList.append(WTF::wrapUnique(new Header(name.lower(), value))); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void FetchHeaderList::set(const String& name, const String& value) { | 36 void FetchHeaderList::set(const String& name, const String& value) { |
| 37 // "To set a name/value (|name|/|value|) pair in a header list (|list|), run | 37 // "To set a name/value (|name|/|value|) pair in a header list (|list|), run |
| 38 // these steps: | 38 // these steps: |
| 39 // 1. Byte lowercase |name|. | 39 // 1. Byte lowercase |name|. |
| 40 // 2. If there are any headers in |list| whose name is |name|, set the value | 40 // 2. If there are any headers in |list| whose name is |name|, set the value |
| 41 // of the first such header to |value| and remove the others. | 41 // of the first such header to |value| and remove the others. |
| 42 // 3. Otherwise, append a new header whose name is |name| and value is | 42 // 3. Otherwise, append a new header whose name is |name| and value is |
| 43 // |value|, to |list|." | 43 // |value|, to |list|." |
| 44 const String lowercasedName = name.lower(); | 44 const String lowercasedName = name.lower(); |
| 45 for (size_t i = 0; i < m_headerList.size(); ++i) { | 45 for (size_t i = 0; i < m_headerList.size(); ++i) { |
| 46 if (m_headerList[i]->first == lowercasedName) { | 46 if (m_headerList[i]->first == lowercasedName) { |
| 47 m_headerList[i]->second = value; | 47 m_headerList[i]->second = value; |
| 48 for (size_t j = i + 1; j < m_headerList.size();) { | 48 for (size_t j = i + 1; j < m_headerList.size();) { |
| 49 if (m_headerList[j]->first == lowercasedName) | 49 if (m_headerList[j]->first == lowercasedName) |
| 50 m_headerList.remove(j); | 50 m_headerList.remove(j); |
| 51 else | 51 else |
| 52 ++j; | 52 ++j; |
| 53 } | 53 } |
| 54 return; | 54 return; |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 m_headerList.append(makeUnique<Header>(lowercasedName, value)); | 57 m_headerList.append(WTF::makeUnique<Header>(lowercasedName, value)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 String FetchHeaderList::extractMIMEType() const { | 60 String FetchHeaderList::extractMIMEType() const { |
| 61 // To extract a MIME type from a header list (headers), run these steps: | 61 // To extract a MIME type from a header list (headers), run these steps: |
| 62 // 1. Let MIMEType be the result of parsing `Content-Type` in headers. | 62 // 1. Let MIMEType be the result of parsing `Content-Type` in headers. |
| 63 String mimeType; | 63 String mimeType; |
| 64 if (!get("Content-Type", mimeType)) { | 64 if (!get("Content-Type", mimeType)) { |
| 65 // 2. If MIMEType is null or failure, return the empty byte sequence. | 65 // 2. If MIMEType is null or failure, return the empty byte sequence. |
| 66 return String(); | 66 return String(); |
| 67 } | 67 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 return isValidHTTPToken(name); | 146 return isValidHTTPToken(name); |
| 147 } | 147 } |
| 148 | 148 |
| 149 bool FetchHeaderList::isValidHeaderValue(const String& value) { | 149 bool FetchHeaderList::isValidHeaderValue(const String& value) { |
| 150 // "A value is a byte sequence that matches the field-value token production | 150 // "A value is a byte sequence that matches the field-value token production |
| 151 // and contains no 0x0A or 0x0D bytes." | 151 // and contains no 0x0A or 0x0D bytes." |
| 152 return isValidHTTPHeaderValue(value); | 152 return isValidHTTPHeaderValue(value); |
| 153 } | 153 } |
| 154 | 154 |
| 155 } // namespace blink | 155 } // namespace blink |
| OLD | NEW |