| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/proxy/proxy_server.h" | 5 #include "net/proxy/proxy_server.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/string_tokenizer.h" | 9 #include "base/string_tokenizer.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 78 } |
| 79 | 79 |
| 80 std::string ProxyServer::host_and_port() const { | 80 std::string ProxyServer::host_and_port() const { |
| 81 // Doesn't make sense to call this if the URI scheme doesn't | 81 // Doesn't make sense to call this if the URI scheme doesn't |
| 82 // have concept of a host. | 82 // have concept of a host. |
| 83 DCHECK(is_valid() && !is_direct()); | 83 DCHECK(is_valid() && !is_direct()); |
| 84 return host_ + ":" + IntToString(port_); | 84 return host_ + ":" + IntToString(port_); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // static | 87 // static |
| 88 ProxyServer ProxyServer::FromURI(const std::string& uri) { | 88 ProxyServer ProxyServer::FromURI(const std::string& uri, |
| 89 return FromURI(uri.begin(), uri.end()); | 89 Scheme default_scheme) { |
| 90 return FromURI(uri.begin(), uri.end(), default_scheme); |
| 90 } | 91 } |
| 91 | 92 |
| 92 // static | 93 // static |
| 93 ProxyServer ProxyServer::FromURI(std::string::const_iterator begin, | 94 ProxyServer ProxyServer::FromURI(std::string::const_iterator begin, |
| 94 std::string::const_iterator end) { | 95 std::string::const_iterator end, |
| 95 // We will default to HTTP if no scheme specifier was given. | 96 Scheme default_scheme) { |
| 96 Scheme scheme = SCHEME_HTTP; | 97 // We will default to |default_scheme| if no scheme specifier was given. |
| 98 Scheme scheme = default_scheme; |
| 97 | 99 |
| 98 // Trim the leading/trailing whitespace. | 100 // Trim the leading/trailing whitespace. |
| 99 HttpUtil::TrimLWS(&begin, &end); | 101 HttpUtil::TrimLWS(&begin, &end); |
| 100 | 102 |
| 101 // Check for [<scheme> "://"] | 103 // Check for [<scheme> "://"] |
| 102 std::string::const_iterator colon = std::find(begin, end, ':'); | 104 std::string::const_iterator colon = std::find(begin, end, ':'); |
| 103 if (colon != end && | 105 if (colon != end && |
| 104 (end - colon) >= 3 && | 106 (end - colon) >= 3 && |
| 105 *(colon + 1) == '/' && | 107 *(colon + 1) == '/' && |
| 106 *(colon + 2) == '/') { | 108 *(colon + 2) == '/') { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 } | 215 } |
| 214 | 216 |
| 215 // Choose a default port number if none was given. | 217 // Choose a default port number if none was given. |
| 216 if (port == -1) | 218 if (port == -1) |
| 217 port = GetDefaultPortForScheme(scheme); | 219 port = GetDefaultPortForScheme(scheme); |
| 218 | 220 |
| 219 return ProxyServer(scheme, host, port); | 221 return ProxyServer(scheme, host, port); |
| 220 } | 222 } |
| 221 | 223 |
| 222 } // namespace net | 224 } // namespace net |
| OLD | NEW |