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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" | 10 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 const size_t kMaxHeaderListSize = 256 * 1024; | 14 const size_t kMaxHeaderListSize = 256 * 1024; |
| 15 | 15 |
| 16 void HeaderCoalescer::OnHeader(base::StringPiece key, base::StringPiece value) { | 16 void HeaderCoalescer::OnHeader(base::StringPiece key, base::StringPiece value) { |
| 17 if (error_seen_) { | 17 if (error_seen_) { |
| 18 return; | 18 return; |
| 19 } | 19 } |
| 20 | 20 |
| 21 if (key.empty()) { | 21 if (key.empty()) { |
| 22 DVLOG(1) << "Header name must not be empty."; | 22 DVLOG(1) << "Header name must not be empty."; |
| 23 error_seen_ = true; | 23 error_seen_ = true; |
| 24 return; | 24 return; |
| 25 } | 25 } |
| 26 | 26 |
| 27 // RFC 7540 Section 8.1.2 says that header field names are ASCII characters. | |
| 28 if (!base::IsStringASCII(key)) { | |
|
asanka
2017/02/22 19:44:13
Consider using something like HttpUtil::IsValidHea
xunjieli
2017/02/22 20:14:51
Done. Thanks for the suggestion!
| |
| 29 error_seen_ = true; | |
| 30 return; | |
| 31 } | |
| 32 | |
| 27 // 32 byte overhead according to RFC 7540 Section 6.5.2. | 33 // 32 byte overhead according to RFC 7540 Section 6.5.2. |
| 28 header_list_size_ += key.size() + value.size() + 32; | 34 header_list_size_ += key.size() + value.size() + 32; |
| 29 if (header_list_size_ > kMaxHeaderListSize) { | 35 if (header_list_size_ > kMaxHeaderListSize) { |
| 30 error_seen_ = true; | 36 error_seen_ = true; |
| 31 return; | 37 return; |
| 32 } | 38 } |
| 33 | 39 |
| 34 if (key[0] == ':') { | 40 if (key[0] == ':') { |
| 35 if (regular_header_seen_) { | 41 if (regular_header_seen_) { |
| 36 error_seen_ = true; | 42 error_seen_ = true; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 DCHECK(headers_valid_); | 75 DCHECK(headers_valid_); |
| 70 headers_valid_ = false; | 76 headers_valid_ = false; |
| 71 return std::move(headers_); | 77 return std::move(headers_); |
| 72 } | 78 } |
| 73 | 79 |
| 74 size_t HeaderCoalescer::EstimateMemoryUsage() const { | 80 size_t HeaderCoalescer::EstimateMemoryUsage() const { |
| 75 return SpdyEstimateMemoryUsage(headers_); | 81 return SpdyEstimateMemoryUsage(headers_); |
| 76 } | 82 } |
| 77 | 83 |
| 78 } // namespace net | 84 } // namespace net |
| OLD | NEW |