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

Side by Side Diff: net/spdy/header_coalescer.cc

Issue 2028473003: Move header-ordering validation from hpack decoder to header validator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix lint errors. Created 4 years, 6 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/spdy/header_coalescer.h ('k') | net/spdy/hpack/hpack_decoder.h » ('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) 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 const size_t kMaxHeaderListSize = 256 * 1024; 11 const size_t kMaxHeaderListSize = 256 * 1024;
12 12
13 void HeaderCoalescer::OnHeader(base::StringPiece key, base::StringPiece value) { 13 void HeaderCoalescer::OnHeader(base::StringPiece key, base::StringPiece value) {
14 if (error_seen_) 14 if (error_seen_) {
15 return; 15 return;
16 }
16 17
17 if (key.empty()) { 18 if (key.empty()) {
18 DVLOG(1) << "Header name must not be empty."; 19 DVLOG(1) << "Header name must not be empty.";
19 error_seen_ = true; 20 error_seen_ = true;
20 return; 21 return;
21 } 22 }
22 23
23 // 32 byte overhead according to RFC 7540 Section 6.5.2. 24 // 32 byte overhead according to RFC 7540 Section 6.5.2.
24 header_list_size_ += key.size() + value.size() + 32; 25 header_list_size_ += key.size() + value.size() + 32;
25 if (header_list_size_ > kMaxHeaderListSize) { 26 if (header_list_size_ > kMaxHeaderListSize) {
26 error_seen_ = true; 27 error_seen_ = true;
27 return; 28 return;
28 } 29 }
29 30
31 if (key[0] == ':') {
32 if (protocol_version_ == HTTP2 && regular_header_seen_) {
33 error_seen_ = true;
34 return;
35 }
36 } else {
37 regular_header_seen_ = true;
38 }
39
30 auto iter = headers_.find(key); 40 auto iter = headers_.find(key);
31 if (iter == headers_.end()) { 41 if (iter == headers_.end()) {
32 headers_[key] = value; 42 headers_[key] = value;
33 } else { 43 } else {
34 // This header had multiple values, so it must be reconstructed. 44 // This header had multiple values, so it must be reconstructed.
35 base::StringPiece v = iter->second; 45 base::StringPiece v = iter->second;
36 std::string s(v.data(), v.length()); 46 std::string s(v.data(), v.length());
37 if (key == "cookie") { 47 if (key == "cookie") {
38 // Obeys section 8.1.2.5 in RFC 7540 for cookie reconstruction. 48 // Obeys section 8.1.2.5 in RFC 7540 for cookie reconstruction.
39 s.append("; "); 49 s.append("; ");
40 } else { 50 } else {
41 base::StringPiece("\0", 1).AppendToString(&s); 51 base::StringPiece("\0", 1).AppendToString(&s);
42 } 52 }
43 value.AppendToString(&s); 53 value.AppendToString(&s);
44 headers_.ReplaceOrAppendHeader(key, s); 54 headers_.ReplaceOrAppendHeader(key, s);
45 } 55 }
46 } 56 }
47 57
48 } // namespace net 58 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/header_coalescer.h ('k') | net/spdy/hpack/hpack_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698