Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: net/quic/core/spdy_utils.cc

Issue 2963863002: Allow trailing headers with duplicate keys. Protected by FLAGS_quic_reloadable_flag_quic_allow_dupl… (Closed)
Patch Set: Rebase Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/core/quic_flags_list.h ('k') | net/quic/core/spdy_utils_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/core/spdy_utils.h" 5 #include "net/quic/core/spdy_utils.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "net/quic/platform/api/quic_flag_utils.h"
11 #include "net/quic/platform/api/quic_flags.h"
10 #include "net/quic/platform/api/quic_logging.h" 12 #include "net/quic/platform/api/quic_logging.h"
11 #include "net/quic/platform/api/quic_map_util.h" 13 #include "net/quic/platform/api/quic_map_util.h"
12 #include "net/quic/platform/api/quic_string_piece.h" 14 #include "net/quic/platform/api/quic_string_piece.h"
13 #include "net/quic/platform/api/quic_text_utils.h" 15 #include "net/quic/platform/api/quic_text_utils.h"
14 #include "net/quic/platform/api/quic_url_utils.h" 16 #include "net/quic/platform/api/quic_url_utils.h"
15 #include "net/spdy/chromium/spdy_flags.h" 17 #include "net/spdy/chromium/spdy_flags.h"
16 #include "net/spdy/core/spdy_frame_builder.h" 18 #include "net/spdy/core/spdy_frame_builder.h"
17 #include "net/spdy/core/spdy_framer.h" 19 #include "net/spdy/core/spdy_framer.h"
18 #include "net/spdy/core/spdy_protocol.h" 20 #include "net/spdy/core/spdy_protocol.h"
19 21
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 return false; 91 return false;
90 } 92 }
91 93
92 QUIC_DVLOG(1) << "Successfully parsed headers: " << headers->DebugString(); 94 QUIC_DVLOG(1) << "Successfully parsed headers: " << headers->DebugString();
93 return true; 95 return true;
94 } 96 }
95 97
96 bool SpdyUtils::CopyAndValidateTrailers(const QuicHeaderList& header_list, 98 bool SpdyUtils::CopyAndValidateTrailers(const QuicHeaderList& header_list,
97 size_t* final_byte_offset, 99 size_t* final_byte_offset,
98 SpdyHeaderBlock* trailers) { 100 SpdyHeaderBlock* trailers) {
101 const bool handle_duplicate_trailers =
102 FLAGS_quic_reloadable_flag_quic_handle_duplicate_trailers;
99 bool found_final_byte_offset = false; 103 bool found_final_byte_offset = false;
100 for (const auto& p : header_list) { 104 for (const auto& p : header_list) {
101 const string& name = p.first; 105 const string& name = p.first;
102 106
103 // Pull out the final offset pseudo header which indicates the number of 107 // Pull out the final offset pseudo header which indicates the number of
104 // response body bytes expected. 108 // response body bytes expected.
105 if (!found_final_byte_offset && name == kFinalOffsetHeaderKey && 109 if (!found_final_byte_offset && name == kFinalOffsetHeaderKey &&
106 QuicTextUtils::StringToSizeT(p.second, final_byte_offset)) { 110 QuicTextUtils::StringToSizeT(p.second, final_byte_offset)) {
107 found_final_byte_offset = true; 111 found_final_byte_offset = true;
108 continue; 112 continue;
109 } 113 }
110 114
111 if (name.empty() || name[0] == ':') { 115 if (name.empty() || name[0] == ':') {
112 QUIC_DLOG(ERROR) 116 QUIC_DLOG(ERROR)
113 << "Trailers must not be empty, and must not contain pseudo-" 117 << "Trailers must not be empty, and must not contain pseudo-"
114 << "headers. Found: '" << name << "'"; 118 << "headers. Found: '" << name << "'";
115 return false; 119 return false;
116 } 120 }
117 121
118 if (QuicTextUtils::ContainsUpperCase(name)) { 122 if (QuicTextUtils::ContainsUpperCase(name)) {
119 QUIC_DLOG(ERROR) << "Malformed header: Header name " << name 123 QUIC_DLOG(ERROR) << "Malformed header: Header name " << name
120 << " contains upper-case characters."; 124 << " contains upper-case characters.";
121 return false; 125 return false;
122 } 126 }
123 127
124 if (trailers->find(name) != trailers->end()) { 128 if (handle_duplicate_trailers) {
125 QUIC_DLOG(ERROR) << "Duplicate header '" << name 129 QUIC_FLAG_COUNT_N(quic_reloadable_flag_quic_handle_duplicate_trailers, 1,
126 << "' found in trailers."; 130 3);
127 return false; 131 trailers->AppendValueOrAddHeader(name, p.second);
132 } else {
133 QUIC_FLAG_COUNT_N(quic_reloadable_flag_quic_handle_duplicate_trailers, 2,
134 3);
135 if (trailers->find(name) != trailers->end()) {
136 QUIC_FLAG_COUNT_N(quic_reloadable_flag_quic_handle_duplicate_trailers,
137 3, 3);
138 QUIC_DLOG(ERROR) << "Duplicate header '" << name
139 << "' found in trailers.";
140 return false;
141 }
142 (*trailers)[name] = p.second;
128 } 143 }
129
130 (*trailers)[name] = p.second;
131 } 144 }
132 145
133 if (!found_final_byte_offset) { 146 if (!found_final_byte_offset) {
134 QUIC_DLOG(ERROR) << "Required key '" << kFinalOffsetHeaderKey 147 QUIC_DLOG(ERROR) << "Required key '" << kFinalOffsetHeaderKey
135 << "' not present"; 148 << "' not present";
136 return false; 149 return false;
137 } 150 }
138 151
139 // TODO(rjshade): Check for other forbidden keys, following the HTTP/2 spec. 152 // TODO(rjshade): Check for other forbidden keys, following the HTTP/2 spec.
140 153
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 (*headers)[":authority"] = url.substr(start); 207 (*headers)[":authority"] = url.substr(start);
195 (*headers)[":path"] = "/"; 208 (*headers)[":path"] = "/";
196 return true; 209 return true;
197 } 210 }
198 (*headers)[":authority"] = url.substr(start, pos - start); 211 (*headers)[":authority"] = url.substr(start, pos - start);
199 (*headers)[":path"] = url.substr(pos); 212 (*headers)[":path"] = url.substr(pos);
200 return true; 213 return true;
201 } 214 }
202 215
203 } // namespace net 216 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_flags_list.h ('k') | net/quic/core/spdy_utils_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698