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/quic/core/quic_header_list.h" | 5 #include "net/quic/core/quic_header_list.h" |
6 | 6 |
7 using std::string; | 7 using std::string; |
8 | 8 |
| 9 #include "net/quic/core/quic_flags.h" |
| 10 #include "net/quic/core/quic_protocol.h" |
| 11 |
9 namespace net { | 12 namespace net { |
10 | 13 |
11 QuicHeaderList::QuicHeaderList() : uncompressed_header_bytes_(0) {} | 14 QuicHeaderList::QuicHeaderList() |
| 15 : max_uncompressed_header_bytes_(kDefaultMaxUncompressedHeaderSize), |
| 16 uncompressed_header_bytes_(0) {} |
12 | 17 |
13 QuicHeaderList::QuicHeaderList(QuicHeaderList&& other) = default; | 18 QuicHeaderList::QuicHeaderList(QuicHeaderList&& other) = default; |
14 | 19 |
15 QuicHeaderList::QuicHeaderList(const QuicHeaderList& other) = default; | 20 QuicHeaderList::QuicHeaderList(const QuicHeaderList& other) = default; |
16 | 21 |
17 QuicHeaderList& QuicHeaderList::operator=(const QuicHeaderList& other) = | 22 QuicHeaderList& QuicHeaderList::operator=(const QuicHeaderList& other) = |
18 default; | 23 default; |
19 | 24 |
20 QuicHeaderList& QuicHeaderList::operator=(QuicHeaderList&& other) = default; | 25 QuicHeaderList& QuicHeaderList::operator=(QuicHeaderList&& other) = default; |
21 | 26 |
22 QuicHeaderList::~QuicHeaderList() {} | 27 QuicHeaderList::~QuicHeaderList() {} |
23 | 28 |
24 void QuicHeaderList::OnHeaderBlockStart() { | 29 void QuicHeaderList::OnHeaderBlockStart() { |
25 QUIC_BUG_IF(uncompressed_header_bytes_ != 0) | 30 QUIC_BUG_IF(uncompressed_header_bytes_ != 0) |
26 << "OnHeaderBlockStart called more than once!"; | 31 << "OnHeaderBlockStart called more than once!"; |
27 } | 32 } |
28 | 33 |
29 void QuicHeaderList::OnHeader(base::StringPiece name, base::StringPiece value) { | 34 void QuicHeaderList::OnHeader(base::StringPiece name, base::StringPiece value) { |
30 header_list_.emplace_back(name.as_string(), value.as_string()); | 35 // Avoid infinte buffering of headers. No longer store headers |
| 36 // once the current headers are over the limit. |
| 37 if (!FLAGS_quic_limit_uncompressed_headers || |
| 38 uncompressed_header_bytes_ == 0 || !header_list_.empty()) { |
| 39 header_list_.emplace_back(name.as_string(), value.as_string()); |
| 40 } |
31 } | 41 } |
32 | 42 |
33 void QuicHeaderList::OnHeaderBlockEnd(size_t uncompressed_header_bytes) { | 43 void QuicHeaderList::OnHeaderBlockEnd(size_t uncompressed_header_bytes) { |
34 uncompressed_header_bytes_ = uncompressed_header_bytes; | 44 OnHeaderBlockEnd(uncompressed_header_bytes, uncompressed_header_bytes); |
35 compressed_header_bytes_ = uncompressed_header_bytes; | |
36 } | 45 } |
37 | 46 |
38 void QuicHeaderList::OnHeaderBlockEnd(size_t uncompressed_header_bytes, | 47 void QuicHeaderList::OnHeaderBlockEnd(size_t uncompressed_header_bytes, |
39 size_t compressed_header_bytes) { | 48 size_t compressed_header_bytes) { |
40 uncompressed_header_bytes_ = uncompressed_header_bytes; | 49 uncompressed_header_bytes_ = uncompressed_header_bytes; |
41 compressed_header_bytes_ = compressed_header_bytes; | 50 compressed_header_bytes_ = compressed_header_bytes; |
| 51 if (FLAGS_quic_limit_uncompressed_headers && |
| 52 uncompressed_header_bytes_ > max_uncompressed_header_bytes_) { |
| 53 Clear(); |
| 54 } |
42 } | 55 } |
43 | 56 |
44 void QuicHeaderList::Clear() { | 57 void QuicHeaderList::Clear() { |
45 header_list_.clear(); | 58 header_list_.clear(); |
46 uncompressed_header_bytes_ = 0; | 59 uncompressed_header_bytes_ = 0; |
47 } | 60 } |
48 | 61 |
49 string QuicHeaderList::DebugString() const { | 62 string QuicHeaderList::DebugString() const { |
50 string s = "{ "; | 63 string s = "{ "; |
51 for (const auto& p : *this) { | 64 for (const auto& p : *this) { |
52 s.append(p.first + "=" + p.second + ", "); | 65 s.append(p.first + "=" + p.second + ", "); |
53 } | 66 } |
54 s.append("}"); | 67 s.append("}"); |
55 return s; | 68 return s; |
56 } | 69 } |
57 | 70 |
58 } // namespace net | 71 } // namespace net |
OLD | NEW |