summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/base/net_util.cc22
-rw-r--r--net/base/net_util.h5
-rw-r--r--net/base/net_util_unittest.cc28
-rw-r--r--net/base/sdch_manager.cc18
-rw-r--r--net/base/sdch_manager.h3
-rw-r--r--net/http/http_auth_handler_digest.cc2
-rw-r--r--net/http/http_network_transaction.cc20
7 files changed, 88 insertions, 10 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index 305cbcc..57448af 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -913,4 +913,26 @@ bool IsPortAllowedByFtp(int port) {
return IsPortAllowedByDefault(port);
}
+std::string GetImplicitPort(const GURL& url) {
+ if (url.has_port())
+ return url.port();
+
+ // TODO(eroman): unify with DefaultPortForScheme()
+ // [url_canon_stdurl.cc]
+
+ static const struct {
+ const char* scheme;
+ const char* port;
+ } scheme_map[] = {
+ { "http", "80" },
+ { "https", "443" },
+ { "ftp", "21" }
+ };
+ for (int i = 0; i < static_cast<int>(ARRAYSIZE_UNSAFE(scheme_map)); ++i) {
+ if (url.SchemeIs(scheme_map[i].scheme))
+ return scheme_map[i].port;
+ }
+ return std::string("");
+}
+
} // namespace net
diff --git a/net/base/net_util.h b/net/base/net_util.h
index db28a76..6ceead7 100644
--- a/net/base/net_util.h
+++ b/net/base/net_util.h
@@ -131,6 +131,11 @@ bool IsPortAllowedByDefault(int port);
// restricted.
bool IsPortAllowedByFtp(int port);
+// Get the port number for the URL. If the URL does not have a port number,
+// then returns the default port for the scheme. If the scheme is unrecognized
+// returns empty string.
+std::string GetImplicitPort(const GURL& url);
+
} // namespace net
#endif // NET_BASE_NET_UTIL_H__
diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc
index 22fb7d4..884f2fe 100644
--- a/net/base/net_util_unittest.cc
+++ b/net/base/net_util_unittest.cc
@@ -698,6 +698,34 @@ TEST(NetUtilTest, GetSuggestedFilename) {
}
}
+TEST(NetUtilTest, GetImplicitPort) {
+ {
+ GURL url("http://foo.bar/baz");
+ EXPECT_STREQ("80", net::GetImplicitPort(url).c_str());
+ }
+ {
+ GURL url("http://foo.bar:443/baz");
+ EXPECT_STREQ("443", net::GetImplicitPort(url).c_str());
+ }
+ {
+ GURL url("https://foo.bar/baz");
+ EXPECT_STREQ("443", net::GetImplicitPort(url).c_str());
+ }
+ {
+ GURL url("https://foo.bar:80/baz");
+ EXPECT_STREQ("80", net::GetImplicitPort(url).c_str());
+ }
+ {
+ // Invalid input.
+ GURL url("file://foobar/baz");
+ EXPECT_STREQ("", net::GetImplicitPort(url).c_str());
+ }
+ {
+ GURL url("ftp://google.com");
+ EXPECT_STREQ("21", net::GetImplicitPort(url).c_str());
+ }
+}
+
// This is currently a windows specific function.
#if defined(OS_WIN)
namespace {
diff --git a/net/base/sdch_manager.cc b/net/base/sdch_manager.cc
index de1e0b0..6c8bce3 100644
--- a/net/base/sdch_manager.cc
+++ b/net/base/sdch_manager.cc
@@ -214,6 +214,18 @@ void SdchManager::UrlSafeBase64Encode(const std::string& input,
// Security functions restricting loads and use of dictionaries.
// static
+int SdchManager::Dictionary::GetPortIncludingDefault(const GURL& url) {
+ std::string port(url.port());
+ if (port.length())
+ return StringToInt(port);
+ if (url.scheme() == "http")
+ return 80; // Default port value.
+ // TODO(jar): If sdch supports other schemes, then write a general function
+ // or surface functionality hidden in url_cannon_stdurl.cc into url_canon.h.
+ return -1;
+}
+
+// static
bool SdchManager::Dictionary::CanSet(const std::string& domain,
const std::string& path,
const std::set<int> ports,
@@ -244,7 +256,7 @@ bool SdchManager::Dictionary::CanSet(const std::string& domain,
// TODO(jar): Enforce item 4 above.
if (!ports.empty()
- && 0 == ports.count(dictionary_url.EffectiveIntPort()))
+ && 0 == ports.count(GetPortIncludingDefault(dictionary_url)))
return false;
return true;
}
@@ -264,7 +276,7 @@ bool SdchManager::Dictionary::CanUse(const GURL referring_url) {
if (!DomainMatch(referring_url, domain_))
return false;
if (!ports_.empty()
- && 0 == ports_.count(referring_url.EffectiveIntPort()))
+ && 0 == ports_.count(GetPortIncludingDefault(referring_url)))
return false;
if (path_.size() && !PathMatch(referring_url.path(), path_))
return false;
@@ -290,7 +302,7 @@ bool SdchManager::Dictionary::CanAdvertise(const GURL& target_url) {
*/
if (!DomainMatch(target_url, domain_))
return false;
- if (!ports_.empty() && 0 == ports_.count(target_url.EffectiveIntPort()))
+ if (!ports_.empty() && 0 == ports_.count(GetPortIncludingDefault(target_url)))
return false;
if (path_.size() && !PathMatch(target_url.path(), path_))
return false;
diff --git a/net/base/sdch_manager.h b/net/base/sdch_manager.h
index ae5f2d3..7926b52 100644
--- a/net/base/sdch_manager.h
+++ b/net/base/sdch_manager.h
@@ -72,6 +72,9 @@ class SdchManager {
const GURL& url() const { return url_; }
const std::string& client_hash() const { return client_hash_; }
+ // For a given URL, get the actual or default port.
+ static int GetPortIncludingDefault(const GURL& url);
+
// Security method to check if we can advertise this dictionary for use
// if the |target_url| returns SDCH compressed data.
bool CanAdvertise(const GURL& target_url);
diff --git a/net/http/http_auth_handler_digest.cc b/net/http/http_auth_handler_digest.cc
index 18f166b..7f351b4 100644
--- a/net/http/http_auth_handler_digest.cc
+++ b/net/http/http_auth_handler_digest.cc
@@ -117,7 +117,7 @@ void HttpAuthHandlerDigest::GetRequestMethodAndPath(
if (target_ == HttpAuth::AUTH_PROXY && url.SchemeIs("https")) {
*method = "CONNECT";
- *path = url.host() + ":" + IntToString(url.EffectiveIntPort());
+ *path = url.host() + ":" + GetImplicitPort(url);
} else {
*method = request->method;
*path = HttpUtil::PathForRequest(url);
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index 52e9328..de3539317 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -247,12 +247,13 @@ void HttpNetworkTransaction::BuildRequestHeaders() {
// in draft-luotonen-web-proxy-tunneling-01.txt and RFC 2817, Sections 5.2 and
// 5.3.
void HttpNetworkTransaction::BuildTunnelRequest() {
+ std::string port = GetImplicitPort(request_->url);
+
// RFC 2616 Section 9 says the Host request-header field MUST accompany all
// HTTP/1.1 requests.
- request_headers_ = StringPrintf("CONNECT %s:%d HTTP/1.1\r\n",
- request_->url.host(), request_->url.EffectiveIntPort());
- request_headers_ += "Host: " + request_->url.host();
- if (request_->url.has_port())
+ request_headers_ = "CONNECT " + request_->url.host() + ":" + port +
+ " HTTP/1.1\r\nHost: " + request_->url.host();
+ if (request_->url.IntPort() != -1)
request_headers_ += ":" + request_->url.port();
request_headers_ += "\r\n";
@@ -452,11 +453,18 @@ int HttpNetworkTransaction::DoResolveHost() {
t.GetNext();
host = t.token();
t.GetNext();
- port = StringToInt(t.token());
+ port = static_cast<int>(StringToInt64(t.token()));
} else {
// Direct connection
host = request_->url.host();
- port = request_->url.EffectiveIntPort();
+ port = request_->url.IntPort();
+ if (port == url_parse::PORT_UNSPECIFIED) {
+ if (using_ssl_) {
+ port = 443; // Default HTTPS port
+ } else {
+ port = 80; // Default HTTP port
+ }
+ }
}
return resolver_.Resolve(host, port, &addresses_, &io_callback_);