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/http/http_util.h" | |
| 10 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" | 11 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" |
| 11 | 12 |
| 12 namespace net { | 13 namespace net { |
| 13 | 14 |
| 14 const size_t kMaxHeaderListSize = 256 * 1024; | 15 const size_t kMaxHeaderListSize = 256 * 1024; |
| 15 | 16 |
| 16 void HeaderCoalescer::OnHeader(base::StringPiece key, base::StringPiece value) { | 17 void HeaderCoalescer::OnHeader(base::StringPiece key, base::StringPiece value) { |
| 17 if (error_seen_) { | 18 if (error_seen_) { |
| 18 return; | 19 return; |
| 19 } | 20 } |
| 20 | 21 |
| 21 if (key.empty()) { | 22 if (key.empty()) { |
| 22 DVLOG(1) << "Header name must not be empty."; | 23 DVLOG(1) << "Header name must not be empty."; |
| 23 error_seen_ = true; | 24 error_seen_ = true; |
| 24 return; | 25 return; |
| 25 } | 26 } |
| 26 | 27 |
| 28 if (!HttpUtil::IsValidHeaderName(key)) { | |
| 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] == ':') { |
|
Biren Roy
2017/02/22 20:26:23
This code block appears intended to handle pseudo-
xunjieli
2017/02/22 22:19:58
I did a brief scan of the spdy code, but I didn't
Biren Roy
2017/02/22 22:34:20
Yeah, I think you're right. Nothing before this la
xunjieli
2017/02/23 16:10:42
Done. Good catch!
| |
| 35 if (regular_header_seen_) { | 41 if (regular_header_seen_) { |
| 36 error_seen_ = true; | 42 error_seen_ = true; |
| 37 return; | 43 return; |
| 38 } | 44 } |
| 39 } else { | 45 } else { |
| 40 regular_header_seen_ = true; | 46 regular_header_seen_ = true; |
| 41 } | 47 } |
| 42 | 48 |
| 43 // End of line delimiter is forbidden according to RFC 7230 Section 3.2. | 49 // End of line delimiter is forbidden according to RFC 7230 Section 3.2. |
| 44 // Line folding, RFC 7230 Section 3.2.4., is a special case of this. | 50 // Line folding, RFC 7230 Section 3.2.4., is a special case of this. |
| (...skipping 24 matching lines...) Expand all 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 |