Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "net/quic/spdy_utils.h" | 5 #include "net/quic/spdy_utils.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 | 112 |
| 113 bool SpdyUtils::CopyAndValidateHeaders(const QuicHeaderList& header_list, | 113 bool SpdyUtils::CopyAndValidateHeaders(const QuicHeaderList& header_list, |
| 114 int64_t* content_length, | 114 int64_t* content_length, |
| 115 SpdyHeaderBlock* headers) { | 115 SpdyHeaderBlock* headers) { |
| 116 for (const auto& p : header_list) { | 116 for (const auto& p : header_list) { |
| 117 const string& name = p.first; | 117 const string& name = p.first; |
| 118 if (name.empty()) { | 118 if (name.empty()) { |
| 119 DVLOG(1) << "Header name must not be empty."; | 119 DVLOG(1) << "Header name must not be empty."; |
| 120 return false; | 120 return false; |
| 121 } | 121 } |
| 122 | |
| 123 if (std::any_of(name.begin(), name.end(), base::IsAsciiUpper<char>)) { | 122 if (std::any_of(name.begin(), name.end(), base::IsAsciiUpper<char>)) { |
| 124 DLOG(ERROR) << "Malformed header: Header name " << name | 123 DLOG(ERROR) << "Malformed header: Header name " << name |
| 125 << " contains upper-case characters."; | 124 << " contains upper-case characters."; |
| 126 return false; | 125 return false; |
| 127 } | 126 } |
| 128 | |
|
Ryan Hamilton
2016/05/24 22:18:46
Can you restore these lines?
dahollings
2016/05/24 22:31:23
Done.
| |
| 129 auto iter = headers->find(name); | 127 auto iter = headers->find(name); |
| 130 if (iter == headers->end()) { | 128 if (iter == headers->end()) { |
| 131 (*headers)[name] = p.second; | 129 (*headers)[name] = p.second; |
| 132 } else if (name == "cookie") { | |
| 133 // Obeys section 8.1.2.5 in RFC 7540 for cookie reconstruction. | |
| 134 headers->ReplaceOrAppendHeader( | |
| 135 name, base::StringPrintf("%s; %s", iter->second.as_string().c_str(), | |
| 136 p.second.c_str())); | |
| 137 } else { | 130 } else { |
| 138 // This header had multiple values, so it must be reconstructed. | 131 // This header had multiple values, so it must be reconstructed. |
| 139 string value = base::StringPrintf( | 132 base::StringPiece v = iter->second; |
| 140 "%s%c%s", iter->second.as_string().c_str(), '\0', p.second.c_str()); | 133 std::string s(v.data(), v.length()); |
| 141 headers->ReplaceOrAppendHeader(name, value); | 134 if (name == "cookie") { |
| 135 // Obeys section 8.1.2.5 in RFC 7540 for cookie reconstruction. | |
| 136 s.append("; "); | |
| 137 } else { | |
| 138 base::StringPiece("\0", 1).AppendToString(&s); | |
| 139 } | |
| 140 s.append(p.second); | |
| 141 headers->ReplaceOrAppendHeader(name, s); | |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 if (ContainsKey(*headers, "content-length")) { | 145 if (ContainsKey(*headers, "content-length")) { |
| 146 // Check whether multiple values are consistent. | 146 // Check whether multiple values are consistent. |
| 147 StringPiece content_length_header = (*headers)["content-length"]; | 147 StringPiece content_length_header = (*headers)["content-length"]; |
| 148 vector<string> values = | 148 vector<string> values = |
| 149 base::SplitString(content_length_header, base::StringPiece("\0", 1), | 149 base::SplitString(content_length_header, base::StringPiece("\0", 1), |
| 150 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 150 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 151 for (const string& value : values) { | 151 for (const string& value : values) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 return GURL(GetUrlFromHeaderBlock(headers)).host(); | 248 return GURL(GetUrlFromHeaderBlock(headers)).host(); |
| 249 } | 249 } |
| 250 | 250 |
| 251 // static | 251 // static |
| 252 bool SpdyUtils::UrlIsValid(const SpdyHeaderBlock& headers) { | 252 bool SpdyUtils::UrlIsValid(const SpdyHeaderBlock& headers) { |
| 253 string url(GetUrlFromHeaderBlock(headers)); | 253 string url(GetUrlFromHeaderBlock(headers)); |
| 254 return url != "" && GURL(url).is_valid(); | 254 return url != "" && GURL(url).is_valid(); |
| 255 } | 255 } |
| 256 | 256 |
| 257 } // namespace net | 257 } // namespace net |
| OLD | NEW |