Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | |
| 8 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
| 9 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "net/http/http_log_util.h" | 13 #include "net/http/http_log_util.h" |
| 13 #include "net/http/http_util.h" | 14 #include "net/http/http_util.h" |
| 14 | 15 |
| 15 namespace net { | 16 namespace net { |
| 16 | 17 |
| 17 const char HttpRequestHeaders::kGetMethod[] = "GET"; | 18 const char HttpRequestHeaders::kGetMethod[] = "GET"; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 } | 80 } |
| 80 | 81 |
| 81 void HttpRequestHeaders::Clear() { | 82 void HttpRequestHeaders::Clear() { |
| 82 headers_.clear(); | 83 headers_.clear(); |
| 83 } | 84 } |
| 84 | 85 |
| 85 void HttpRequestHeaders::SetHeader(const base::StringPiece& key, | 86 void HttpRequestHeaders::SetHeader(const base::StringPiece& key, |
| 86 const base::StringPiece& value) { | 87 const base::StringPiece& value) { |
| 87 DCHECK(HttpUtil::IsValidHeaderName(key.as_string())); | 88 DCHECK(HttpUtil::IsValidHeaderName(key.as_string())); |
| 88 DCHECK(HttpUtil::IsValidHeaderValue(value.as_string())); | 89 DCHECK(HttpUtil::IsValidHeaderValue(value.as_string())); |
| 90 UMA_HISTOGRAM_BOOLEAN("Net.HttpRequestHeaderValueValidInRFC7230", | |
| 91 HttpUtil::IsValidHeaderValueRFC7230(value.as_string())); | |
|
davidben
2015/09/29 16:32:59
This makes an unnecessary copy. The lines above do
hiroshige
2015/09/30 08:19:23
Done by using StringPiece.
| |
| 89 HeaderVector::iterator it = FindHeader(key); | 92 HeaderVector::iterator it = FindHeader(key); |
| 90 if (it != headers_.end()) | 93 if (it != headers_.end()) |
| 91 it->value.assign(value.data(), value.size()); | 94 it->value.assign(value.data(), value.size()); |
| 92 else | 95 else |
| 93 headers_.push_back(HeaderKeyValuePair(key, value)); | 96 headers_.push_back(HeaderKeyValuePair(key, value)); |
| 94 } | 97 } |
| 95 | 98 |
| 96 void HttpRequestHeaders::SetHeaderIfMissing(const base::StringPiece& key, | 99 void HttpRequestHeaders::SetHeaderIfMissing(const base::StringPiece& key, |
| 97 const base::StringPiece& value) { | 100 const base::StringPiece& value) { |
| 98 DCHECK(HttpUtil::IsValidHeaderName(key.as_string())); | 101 DCHECK(HttpUtil::IsValidHeaderName(key.as_string())); |
| 99 DCHECK(HttpUtil::IsValidHeaderValue(value.as_string())); | 102 DCHECK(HttpUtil::IsValidHeaderValue(value.as_string())); |
| 103 UMA_HISTOGRAM_BOOLEAN("Net.HttpRequestHeaderValueValidInRFC7230", | |
| 104 HttpUtil::IsValidHeaderValueRFC7230(value.as_string())); | |
| 100 HeaderVector::iterator it = FindHeader(key); | 105 HeaderVector::iterator it = FindHeader(key); |
| 101 if (it == headers_.end()) | 106 if (it == headers_.end()) |
| 102 headers_.push_back(HeaderKeyValuePair(key, value)); | 107 headers_.push_back(HeaderKeyValuePair(key, value)); |
| 103 } | 108 } |
| 104 | 109 |
| 105 void HttpRequestHeaders::RemoveHeader(const base::StringPiece& key) { | 110 void HttpRequestHeaders::RemoveHeader(const base::StringPiece& key) { |
| 106 HeaderVector::iterator it = FindHeader(key); | 111 HeaderVector::iterator it = FindHeader(key); |
| 107 if (it != headers_.end()) | 112 if (it != headers_.end()) |
| 108 headers_.erase(it); | 113 headers_.erase(it); |
| 109 } | 114 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 for (HeaderVector::const_iterator it = headers_.begin(); | 258 for (HeaderVector::const_iterator it = headers_.begin(); |
| 254 it != headers_.end(); ++it) { | 259 it != headers_.end(); ++it) { |
| 255 if (base::EqualsCaseInsensitiveASCII(key, it->key)) | 260 if (base::EqualsCaseInsensitiveASCII(key, it->key)) |
| 256 return it; | 261 return it; |
| 257 } | 262 } |
| 258 | 263 |
| 259 return headers_.end(); | 264 return headers_.end(); |
| 260 } | 265 } |
| 261 | 266 |
| 262 } // namespace net | 267 } // namespace net |
| OLD | NEW |