| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/string_split.h" | 8 #include "base/string_split.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "net/http/http_util.h" | 10 #include "net/http/http_util.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 if (it == headers_.end()) | 70 if (it == headers_.end()) |
| 71 return false; | 71 return false; |
| 72 out->assign(it->value); | 72 out->assign(it->value); |
| 73 return true; | 73 return true; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void HttpRequestHeaders::Clear() { | 76 void HttpRequestHeaders::Clear() { |
| 77 headers_.clear(); | 77 headers_.clear(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void HttpRequestHeaders::SetHeaderIfMissing(const base::StringPiece& key, | |
| 81 const base::StringPiece& value) { | |
| 82 HeaderVector::iterator it = FindHeader(key); | |
| 83 if (it == headers_.end()) | |
| 84 headers_.push_back(HeaderKeyValuePair(key.as_string(), value.as_string())); | |
| 85 } | |
| 86 | |
| 87 void HttpRequestHeaders::SetHeader(const base::StringPiece& key, | 80 void HttpRequestHeaders::SetHeader(const base::StringPiece& key, |
| 88 const base::StringPiece& value) { | 81 const base::StringPiece& value) { |
| 89 HeaderVector::iterator it = FindHeader(key); | 82 HeaderVector::iterator it = FindHeader(key); |
| 90 if (it != headers_.end()) | 83 if (it != headers_.end()) |
| 91 it->value = value.as_string(); | 84 it->value = value.as_string(); |
| 92 else | 85 else |
| 93 headers_.push_back(HeaderKeyValuePair(key.as_string(), value.as_string())); | 86 headers_.push_back(HeaderKeyValuePair(key.as_string(), value.as_string())); |
| 94 } | 87 } |
| 95 | 88 |
| 89 void HttpRequestHeaders::SetHeaderIfMissing(const base::StringPiece& key, |
| 90 const base::StringPiece& value) { |
| 91 HeaderVector::iterator it = FindHeader(key); |
| 92 if (it == headers_.end()) |
| 93 headers_.push_back(HeaderKeyValuePair(key.as_string(), value.as_string())); |
| 94 } |
| 95 |
| 96 void HttpRequestHeaders::RemoveHeader(const base::StringPiece& key) { | 96 void HttpRequestHeaders::RemoveHeader(const base::StringPiece& key) { |
| 97 HeaderVector::iterator it = FindHeader(key); | 97 HeaderVector::iterator it = FindHeader(key); |
| 98 if (it != headers_.end()) | 98 if (it != headers_.end()) |
| 99 headers_.erase(it); | 99 headers_.erase(it); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void HttpRequestHeaders::AddHeaderFromString( | 102 void HttpRequestHeaders::AddHeaderFromString( |
| 103 const base::StringPiece& header_line) { | 103 const base::StringPiece& header_line) { |
| 104 DCHECK_EQ(std::string::npos, header_line.find("\r\n")) | 104 DCHECK_EQ(std::string::npos, header_line.find("\r\n")) |
| 105 << "\"" << header_line << "\" contains CRLF."; | 105 << "\"" << header_line << "\" contains CRLF."; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 it != headers_.end(); ++it) { | 197 it != headers_.end(); ++it) { |
| 198 if (key.length() == it->key.length() && | 198 if (key.length() == it->key.length() && |
| 199 !base::strncasecmp(key.data(), it->key.data(), key.length())) | 199 !base::strncasecmp(key.data(), it->key.data(), key.length())) |
| 200 return it; | 200 return it; |
| 201 } | 201 } |
| 202 | 202 |
| 203 return headers_.end(); | 203 return headers_.end(); |
| 204 } | 204 } |
| 205 | 205 |
| 206 } // namespace net | 206 } // namespace net |
| OLD | NEW |