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/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 out->assign(it->value); | 77 out->assign(it->value); |
78 return true; | 78 return true; |
79 } | 79 } |
80 | 80 |
81 void HttpRequestHeaders::Clear() { | 81 void HttpRequestHeaders::Clear() { |
82 headers_.clear(); | 82 headers_.clear(); |
83 } | 83 } |
84 | 84 |
85 void HttpRequestHeaders::SetHeader(const base::StringPiece& key, | 85 void HttpRequestHeaders::SetHeader(const base::StringPiece& key, |
86 const base::StringPiece& value) { | 86 const base::StringPiece& value) { |
| 87 DCHECK(HttpUtil::IsValidHeaderName(key.as_string())); |
| 88 DCHECK(HttpUtil::IsValidHeaderValue(value.as_string())); |
87 HeaderVector::iterator it = FindHeader(key); | 89 HeaderVector::iterator it = FindHeader(key); |
88 if (it != headers_.end()) | 90 if (it != headers_.end()) |
89 it->value.assign(value.data(), value.size()); | 91 it->value.assign(value.data(), value.size()); |
90 else | 92 else |
91 headers_.push_back(HeaderKeyValuePair(key, value)); | 93 headers_.push_back(HeaderKeyValuePair(key, value)); |
92 } | 94 } |
93 | 95 |
94 void HttpRequestHeaders::SetHeaderIfMissing(const base::StringPiece& key, | 96 void HttpRequestHeaders::SetHeaderIfMissing(const base::StringPiece& key, |
95 const base::StringPiece& value) { | 97 const base::StringPiece& value) { |
| 98 DCHECK(HttpUtil::IsValidHeaderName(key.as_string())); |
| 99 DCHECK(HttpUtil::IsValidHeaderValue(value.as_string())); |
96 HeaderVector::iterator it = FindHeader(key); | 100 HeaderVector::iterator it = FindHeader(key); |
97 if (it == headers_.end()) | 101 if (it == headers_.end()) |
98 headers_.push_back(HeaderKeyValuePair(key, value)); | 102 headers_.push_back(HeaderKeyValuePair(key, value)); |
99 } | 103 } |
100 | 104 |
101 void HttpRequestHeaders::RemoveHeader(const base::StringPiece& key) { | 105 void HttpRequestHeaders::RemoveHeader(const base::StringPiece& key) { |
102 HeaderVector::iterator it = FindHeader(key); | 106 HeaderVector::iterator it = FindHeader(key); |
103 if (it != headers_.end()) | 107 if (it != headers_.end()) |
104 headers_.erase(it); | 108 headers_.erase(it); |
105 } | 109 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 it != headers_.end(); ++it) { | 255 it != headers_.end(); ++it) { |
252 if (key.length() == it->key.length() && | 256 if (key.length() == it->key.length() && |
253 !base::strncasecmp(key.data(), it->key.data(), key.length())) | 257 !base::strncasecmp(key.data(), it->key.data(), key.length())) |
254 return it; | 258 return it; |
255 } | 259 } |
256 | 260 |
257 return headers_.end(); | 261 return headers_.end(); |
258 } | 262 } |
259 | 263 |
260 } // namespace net | 264 } // namespace net |
OLD | NEW |