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

Side by Side Diff: net/http/http_request_headers.cc

Issue 2428103002: Escape non-ASCII Request header values before attaching them as a NetLog string. (Closed)
Patch Set: Address Matt's feedback Created 4 years, 2 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 | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/http/http_request_headers.h" 5 #include "net/http/http_request_headers.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "net/base/escape.h"
14 #include "net/http/http_log_util.h" 15 #include "net/http/http_log_util.h"
15 #include "net/http/http_util.h" 16 #include "net/http/http_util.h"
16 #include "net/log/net_log_capture_mode.h" 17 #include "net/log/net_log_capture_mode.h"
17 18
18 namespace net { 19 namespace net {
19 20
20 const char HttpRequestHeaders::kGetMethod[] = "GET"; 21 const char HttpRequestHeaders::kGetMethod[] = "GET";
21 const char HttpRequestHeaders::kAcceptCharset[] = "Accept-Charset"; 22 const char HttpRequestHeaders::kAcceptCharset[] = "Accept-Charset";
22 const char HttpRequestHeaders::kAcceptEncoding[] = "Accept-Encoding"; 23 const char HttpRequestHeaders::kAcceptEncoding[] = "Accept-Encoding";
23 const char HttpRequestHeaders::kAcceptLanguage[] = "Accept-Language"; 24 const char HttpRequestHeaders::kAcceptLanguage[] = "Accept-Language";
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 } 182 }
182 } 183 }
183 output.append("\r\n"); 184 output.append("\r\n");
184 return output; 185 return output;
185 } 186 }
186 187
187 std::unique_ptr<base::Value> HttpRequestHeaders::NetLogCallback( 188 std::unique_ptr<base::Value> HttpRequestHeaders::NetLogCallback(
188 const std::string* request_line, 189 const std::string* request_line,
189 NetLogCaptureMode capture_mode) const { 190 NetLogCaptureMode capture_mode) const {
190 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 191 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
191 dict->SetString("line", *request_line); 192 dict->SetString("line", EscapeNonASCII(*request_line));
192 base::ListValue* headers = new base::ListValue(); 193 base::ListValue* headers = new base::ListValue();
193 for (HeaderVector::const_iterator it = headers_.begin(); 194 for (HeaderVector::const_iterator it = headers_.begin(); it != headers_.end();
194 it != headers_.end(); ++it) { 195 ++it) {
195 std::string log_value = 196 std::string log_value =
196 ElideHeaderValueForNetLog(capture_mode, it->key, it->value); 197 ElideHeaderValueForNetLog(capture_mode, it->key, it->value);
197 headers->AppendString( 198 std::string escaped_name = EscapeNonASCII(it->key);
198 base::StringPrintf("%s: %s", it->key.c_str(), log_value.c_str())); 199 std::string escaped_value = EscapeNonASCII(log_value);
200 headers->AppendString(base::StringPrintf("%s: %s", escaped_name.c_str(),
201 escaped_value.c_str()));
199 } 202 }
200 dict->Set("headers", headers); 203 dict->Set("headers", headers);
201 return std::move(dict); 204 return std::move(dict);
202 } 205 }
203 206
204 // static 207 // static
205 bool HttpRequestHeaders::FromNetLogParam(const base::Value* event_param, 208 bool HttpRequestHeaders::FromNetLogParam(const base::Value* event_param,
206 HttpRequestHeaders* headers, 209 HttpRequestHeaders* headers,
207 std::string* request_line) { 210 std::string* request_line) {
208 headers->Clear(); 211 headers->Clear();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 for (HeaderVector::const_iterator it = headers_.begin(); 251 for (HeaderVector::const_iterator it = headers_.begin();
249 it != headers_.end(); ++it) { 252 it != headers_.end(); ++it) {
250 if (base::EqualsCaseInsensitiveASCII(key, it->key)) 253 if (base::EqualsCaseInsensitiveASCII(key, it->key))
251 return it; 254 return it;
252 } 255 }
253 256
254 return headers_.end(); 257 return headers_.end();
255 } 258 }
256 259
257 } // namespace net 260 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698