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

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

Issue 2832973003: Split net/spdy into core and chromium subdirectories. (Closed)
Patch Set: Fix some more build rules. Created 3 years, 8 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/header_coalescer_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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/spdy/header_coalescer.h"
6
7 #include <utility>
8
9 #include "base/strings/string_util.h"
10 #include "net/http/http_util.h"
11 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h"
12 #include "net/spdy/platform/api/spdy_string.h"
13
14 namespace net {
15
16 const size_t kMaxHeaderListSize = 256 * 1024;
17
18 void HeaderCoalescer::OnHeader(SpdyStringPiece key, SpdyStringPiece value) {
19 if (error_seen_) {
20 return;
21 }
22
23 if (key.empty()) {
24 DVLOG(1) << "Header name must not be empty.";
25 error_seen_ = true;
26 return;
27 }
28
29 SpdyStringPiece key_name = key;
30 if (key[0] == ':') {
31 if (regular_header_seen_) {
32 error_seen_ = true;
33 return;
34 }
35 key_name.remove_prefix(1);
36 } else if (!regular_header_seen_) {
37 regular_header_seen_ = true;
38 }
39
40 if (!HttpUtil::IsValidHeaderName(key_name)) {
41 error_seen_ = true;
42 return;
43 }
44
45 // 32 byte overhead according to RFC 7540 Section 6.5.2.
46 header_list_size_ += key.size() + value.size() + 32;
47 if (header_list_size_ > kMaxHeaderListSize) {
48 error_seen_ = true;
49 return;
50 }
51
52 // End of line delimiter is forbidden according to RFC 7230 Section 3.2.
53 // Line folding, RFC 7230 Section 3.2.4., is a special case of this.
54 if (value.find("\r\n") != SpdyStringPiece::npos) {
55 error_seen_ = true;
56 return;
57 }
58
59 auto iter = headers_.find(key);
60 if (iter == headers_.end()) {
61 headers_[key] = value;
62 } else {
63 // This header had multiple values, so it must be reconstructed.
64 SpdyStringPiece v = iter->second;
65 SpdyString s(v.data(), v.length());
66 if (key == "cookie") {
67 // Obeys section 8.1.2.5 in RFC 7540 for cookie reconstruction.
68 s.append("; ");
69 } else {
70 SpdyStringPiece("\0", 1).AppendToString(&s);
71 }
72 value.AppendToString(&s);
73 headers_[key] = s;
74 }
75 }
76
77 SpdyHeaderBlock HeaderCoalescer::release_headers() {
78 DCHECK(headers_valid_);
79 headers_valid_ = false;
80 return std::move(headers_);
81 }
82
83 size_t HeaderCoalescer::EstimateMemoryUsage() const {
84 return SpdyEstimateMemoryUsage(headers_);
85 }
86
87 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/header_coalescer.h ('k') | net/spdy/header_coalescer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698