| 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/base/host_port_pair.h" | 5 #include "net/base/host_port_pair.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 return HostPortPair(); | 40 return HostPortPair(); |
| 41 if (!IsPortValid(port)) | 41 if (!IsPortValid(port)) |
| 42 return HostPortPair(); | 42 return HostPortPair(); |
| 43 HostPortPair host_port_pair; | 43 HostPortPair host_port_pair; |
| 44 host_port_pair.set_host(key_port[0]); | 44 host_port_pair.set_host(key_port[0]); |
| 45 host_port_pair.set_port(static_cast<uint16>(port)); | 45 host_port_pair.set_port(static_cast<uint16>(port)); |
| 46 return host_port_pair; | 46 return host_port_pair; |
| 47 } | 47 } |
| 48 | 48 |
| 49 std::string HostPortPair::ToString() const { | 49 std::string HostPortPair::ToString() const { |
| 50 return base::StringPrintf("%s:%u", HostForURL().c_str(), port_); | 50 std::string ret(HostForURL()); |
| 51 ret += ':'; |
| 52 ret += base::IntToString(port_); |
| 53 return ret; |
| 51 } | 54 } |
| 52 | 55 |
| 53 std::string HostPortPair::HostForURL() const { | 56 std::string HostPortPair::HostForURL() const { |
| 54 // TODO(rtenneti): Add support for |host| to have '\0'. | 57 // TODO(rtenneti): Add support for |host| to have '\0'. |
| 55 if (host_.find('\0') != std::string::npos) { | 58 if (host_.find('\0') != std::string::npos) { |
| 56 std::string host_for_log(host_); | 59 std::string host_for_log(host_); |
| 57 size_t nullpos; | 60 size_t nullpos; |
| 58 while ((nullpos = host_for_log.find('\0')) != std::string::npos) { | 61 while ((nullpos = host_for_log.find('\0')) != std::string::npos) { |
| 59 host_for_log.replace(nullpos, 1, "%00"); | 62 host_for_log.replace(nullpos, 1, "%00"); |
| 60 } | 63 } |
| 61 LOG(DFATAL) << "Host has a null char: " << host_for_log; | 64 LOG(DFATAL) << "Host has a null char: " << host_for_log; |
| 62 } | 65 } |
| 63 // Check to see if the host is an IPv6 address. If so, added brackets. | 66 // Check to see if the host is an IPv6 address. If so, added brackets. |
| 64 if (host_.find(':') != std::string::npos) { | 67 if (host_.find(':') != std::string::npos) { |
| 65 DCHECK_NE(host_[0], '['); | 68 DCHECK_NE(host_[0], '['); |
| 66 return base::StringPrintf("[%s]", host_.c_str()); | 69 return base::StringPrintf("[%s]", host_.c_str()); |
| 67 } | 70 } |
| 68 | 71 |
| 69 return host_; | 72 return host_; |
| 70 } | 73 } |
| 71 | 74 |
| 72 } // namespace net | 75 } // namespace net |
| OLD | NEW |