| 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 <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" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 110 } |
| 111 | 111 |
| 112 void HttpRequestHeaders::RemoveHeader(const base::StringPiece& key) { | 112 void HttpRequestHeaders::RemoveHeader(const base::StringPiece& key) { |
| 113 HeaderVector::iterator it = FindHeader(key); | 113 HeaderVector::iterator it = FindHeader(key); |
| 114 if (it != headers_.end()) | 114 if (it != headers_.end()) |
| 115 headers_.erase(it); | 115 headers_.erase(it); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void HttpRequestHeaders::AddHeaderFromString( | 118 void HttpRequestHeaders::AddHeaderFromString( |
| 119 const base::StringPiece& header_line) { | 119 const base::StringPiece& header_line) { |
| 120 DCHECK_EQ(std::string::npos, header_line.find("\r\n")) | 120 DCHECK_EQ(std::string::npos, header_line.find_first_of("\r\n")) |
| 121 << "\"" << header_line << "\" contains CRLF."; | 121 << "\"" << header_line << "\" contains CRLF."; |
| 122 | 122 |
| 123 const std::string::size_type key_end_index = header_line.find(":"); | 123 const std::string::size_type key_end_index = header_line.find(":"); |
| 124 if (key_end_index == std::string::npos) { | 124 if (key_end_index == std::string::npos) { |
| 125 LOG(DFATAL) << "\"" << header_line << "\" is missing colon delimiter."; | 125 LOG(DFATAL) << "\"" << header_line << "\" is missing colon delimiter."; |
| 126 return; | 126 return; |
| 127 } | 127 } |
| 128 | 128 |
| 129 if (key_end_index == 0) { | 129 if (key_end_index == 0) { |
| 130 LOG(DFATAL) << "\"" << header_line << "\" is missing header key."; | 130 LOG(DFATAL) << "\"" << header_line << "\" is missing header key."; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 154 } | 154 } |
| 155 } else if (value_index == header_line.size()) { | 155 } else if (value_index == header_line.size()) { |
| 156 SetHeader(header_key, ""); | 156 SetHeader(header_key, ""); |
| 157 } else { | 157 } else { |
| 158 NOTREACHED(); | 158 NOTREACHED(); |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 | 161 |
| 162 void HttpRequestHeaders::AddHeadersFromString( | 162 void HttpRequestHeaders::AddHeadersFromString( |
| 163 const base::StringPiece& headers) { | 163 const base::StringPiece& headers) { |
| 164 for (const base::StringPiece& header : base::SplitStringPieceUsingSubstr( | 164 for (const base::StringPiece& header : base::SplitStringPiece( |
| 165 headers, "\r\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { | 165 headers, "\r\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { |
| 166 AddHeaderFromString(header); | 166 AddHeaderFromString(header); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 | 169 |
| 170 void HttpRequestHeaders::MergeFrom(const HttpRequestHeaders& other) { | 170 void HttpRequestHeaders::MergeFrom(const HttpRequestHeaders& other) { |
| 171 for (HeaderVector::const_iterator it = other.headers_.begin(); | 171 for (HeaderVector::const_iterator it = other.headers_.begin(); |
| 172 it != other.headers_.end(); ++it ) { | 172 it != other.headers_.end(); ++it ) { |
| 173 SetHeader(it->key, it->value); | 173 SetHeader(it->key, it->value); |
| 174 } | 174 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 for (HeaderVector::const_iterator it = headers_.begin(); | 253 for (HeaderVector::const_iterator it = headers_.begin(); |
| 254 it != headers_.end(); ++it) { | 254 it != headers_.end(); ++it) { |
| 255 if (base::EqualsCaseInsensitiveASCII(key, it->key)) | 255 if (base::EqualsCaseInsensitiveASCII(key, it->key)) |
| 256 return it; | 256 return it; |
| 257 } | 257 } |
| 258 | 258 |
| 259 return headers_.end(); | 259 return headers_.end(); |
| 260 } | 260 } |
| 261 | 261 |
| 262 } // namespace net | 262 } // namespace net |
| OLD | NEW |