Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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/spdy/header_coalescer.h" | 5 #include "net/spdy/header_coalescer.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 | 8 |
| 9 namespace net { | 9 namespace net { |
| 10 | 10 |
| 11 void HeaderCoalescer::OnHeader(base::StringPiece key, base::StringPiece value) { | 11 void HeaderCoalescer::OnHeader(base::StringPiece key, base::StringPiece value) { |
|
Bence
2016/06/20 12:11:27
Please return if |error_seen_| first thing in this
| |
| 12 if (key.empty()) { | 12 if (key.empty()) { |
| 13 DVLOG(1) << "Header name must not be empty."; | 13 DVLOG(1) << "Header name must not be empty."; |
| 14 error_seen_ = true; | 14 error_seen_ = true; |
| 15 return; | 15 return; |
| 16 } | 16 } |
| 17 | 17 |
| 18 if (key[0] == ':') { | |
| 19 if (regular_header_seen_) { | |
| 20 error_seen_ = true; | |
| 21 return; | |
| 22 } | |
| 23 } else { | |
| 24 regular_header_seen_ = true; | |
| 25 } | |
| 26 | |
| 18 auto iter = headers_.find(key); | 27 auto iter = headers_.find(key); |
| 19 if (iter == headers_.end()) { | 28 if (iter == headers_.end()) { |
| 20 headers_[key] = value; | 29 headers_[key] = value; |
| 21 } else { | 30 } else { |
| 22 // This header had multiple values, so it must be reconstructed. | 31 // This header had multiple values, so it must be reconstructed. |
| 23 base::StringPiece v = iter->second; | 32 base::StringPiece v = iter->second; |
| 24 std::string s(v.data(), v.length()); | 33 std::string s(v.data(), v.length()); |
| 25 if (key == "cookie") { | 34 if (key == "cookie") { |
| 26 // Obeys section 8.1.2.5 in RFC 7540 for cookie reconstruction. | 35 // Obeys section 8.1.2.5 in RFC 7540 for cookie reconstruction. |
| 27 s.append("; "); | 36 s.append("; "); |
| 28 } else { | 37 } else { |
| 29 base::StringPiece("\0", 1).AppendToString(&s); | 38 base::StringPiece("\0", 1).AppendToString(&s); |
| 30 } | 39 } |
| 31 value.AppendToString(&s); | 40 value.AppendToString(&s); |
| 32 headers_.ReplaceOrAppendHeader(key, s); | 41 headers_.ReplaceOrAppendHeader(key, s); |
| 33 } | 42 } |
| 34 } | 43 } |
| 35 | 44 |
| 36 } // namespace net | 45 } // namespace net |
| OLD | NEW |