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

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

Issue 1976473003: Fixes header translation between SpdyHeaderBlock and other data structures. Not protected. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@121370394
Patch Set: Created 4 years, 7 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 | « no previous file | net/quic/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/spdy_utils.h" 5 #include "net/quic/spdy_utils.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h"
14 #include "net/spdy/spdy_frame_builder.h" 15 #include "net/spdy/spdy_frame_builder.h"
15 #include "net/spdy/spdy_framer.h" 16 #include "net/spdy/spdy_framer.h"
16 #include "net/spdy/spdy_protocol.h" 17 #include "net/spdy/spdy_protocol.h"
17 #include "url/gurl.h" 18 #include "url/gurl.h"
18 19
19 using base::StringPiece; 20 using base::StringPiece;
20 using std::string; 21 using std::string;
21 using std::vector; 22 using std::vector;
22 23
23 namespace net { 24 namespace net {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 DVLOG(1) << "Header name must not be empty."; 119 DVLOG(1) << "Header name must not be empty.";
119 return false; 120 return false;
120 } 121 }
121 122
122 if (std::any_of(name.begin(), name.end(), base::IsAsciiUpper<char>)) { 123 if (std::any_of(name.begin(), name.end(), base::IsAsciiUpper<char>)) {
123 DLOG(ERROR) << "Malformed header: Header name " << name 124 DLOG(ERROR) << "Malformed header: Header name " << name
124 << " contains upper-case characters."; 125 << " contains upper-case characters.";
125 return false; 126 return false;
126 } 127 }
127 128
128 if (headers->find(name) != headers->end()) { 129 auto iter = headers->find(name);
129 DLOG(ERROR) << "Duplicate header '" << name << "' found."; 130 if (iter == headers->end()) {
130 return false; 131 (*headers)[name] = p.second;
132 } else {
133 // This header had multiple values, so it must be reconstructed.
134 string value = base::StringPrintf(
135 "%s%c%s", iter->second.as_string().c_str(), '\0', p.second.c_str());
136 headers->ReplaceOrAppendHeader(name, value);
131 } 137 }
132
133 (*headers)[name] = p.second;
134 } 138 }
135 139
136 if (ContainsKey(*headers, "content-length")) { 140 if (ContainsKey(*headers, "content-length")) {
137 // Check whether multiple values are consistent. 141 // Check whether multiple values are consistent.
138 StringPiece content_length_header = (*headers)["content-length"]; 142 StringPiece content_length_header = (*headers)["content-length"];
139 vector<string> values = 143 vector<string> values =
140 base::SplitString(content_length_header, base::StringPiece("\0", 1), 144 base::SplitString(content_length_header, base::StringPiece("\0", 1),
141 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 145 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
142 for (const string& value : values) { 146 for (const string& value : values) {
143 int new_value; 147 int new_value;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 return GURL(GetUrlFromHeaderBlock(headers)).host(); 243 return GURL(GetUrlFromHeaderBlock(headers)).host();
240 } 244 }
241 245
242 // static 246 // static
243 bool SpdyUtils::UrlIsValid(const SpdyHeaderBlock& headers) { 247 bool SpdyUtils::UrlIsValid(const SpdyHeaderBlock& headers) {
244 string url(GetUrlFromHeaderBlock(headers)); 248 string url(GetUrlFromHeaderBlock(headers));
245 return url != "" && GURL(url).is_valid(); 249 return url != "" && GURL(url).is_valid();
246 } 250 }
247 251
248 } // namespace net 252 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/quic/spdy_utils_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698