summaryrefslogtreecommitdiffstats
path: root/net/http
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-18 23:39:29 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-18 23:39:29 +0000
commitda81f13c4d59797f9a83c35a8acc544138df499f (patch)
tree0cafabeb7e54071577bce8a0ef7f2c8e6eceedac /net/http
parent2428a3e48d06d5ad68581c9e62df30a49bafa872 (diff)
downloadchromium_src-da81f13c4d59797f9a83c35a8acc544138df499f.zip
chromium_src-da81f13c4d59797f9a83c35a8acc544138df499f.tar.gz
chromium_src-da81f13c4d59797f9a83c35a8acc544138df499f.tar.bz2
Send user agent with CONNECT requests.
BUG=52591 TEST=HttpNetworkTransactionTest.BuildTunnelRequest_UserAgent Review URL: http://codereview.chromium.org/3164024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56621 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r--net/http/http_network_transaction.cc4
-rw-r--r--net/http/http_network_transaction_unittest.cc38
-rw-r--r--net/http/http_proxy_client_socket.cc6
-rw-r--r--net/http/http_proxy_client_socket.h4
-rw-r--r--net/http/http_proxy_client_socket_pool.cc3
-rw-r--r--net/http/http_proxy_client_socket_pool.h6
-rw-r--r--net/http/http_proxy_client_socket_pool_unittest.cc4
7 files changed, 60 insertions, 5 deletions
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index 05c32f2..6b32d2f 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -763,8 +763,12 @@ int HttpNetworkTransaction::DoInitConnection() {
authentication_url = UpgradeUrlToHttps(authentication_url);
}
establishing_tunnel_ = using_ssl_;
+ std::string user_agent;
+ request_->extra_headers.GetHeader(HttpRequestHeaders::kUserAgent,
+ &user_agent);
http_proxy_params = new HttpProxySocketParams(proxy_tcp_params,
authentication_url,
+ user_agent,
endpoint_,
session_, using_ssl_);
} else {
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index dc7c842..d3cb28a 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -3575,6 +3575,44 @@ TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) {
EXPECT_EQ(OK, rv);
}
+TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) {
+ SessionDependencies session_deps(CreateFixedProxyService("myproxy:70"));
+ scoped_ptr<HttpTransaction> trans(
+ new HttpNetworkTransaction(CreateSession(&session_deps)));
+
+ HttpRequestInfo request;
+ request.method = "GET";
+ request.url = GURL("https://www.google.com/");
+ request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent,
+ "Chromium Ultra Awesome X Edition");
+
+ MockWrite data_writes[] = {
+ MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
+ "Host: www.google.com\r\n"
+ "Proxy-Connection: keep-alive\r\n"
+ "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"),
+ };
+ MockRead data_reads[] = {
+ // Return an error, so the transaction stops here (this test isn't
+ // interested in the rest).
+ MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
+ MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
+ MockRead("Proxy-Connection: close\r\n\r\n"),
+ };
+
+ StaticSocketDataProvider data(data_reads, arraysize(data_reads),
+ data_writes, arraysize(data_writes));
+ session_deps.socket_factory.AddSocketDataProvider(&data);
+
+ TestCompletionCallback callback;
+
+ int rv = trans->Start(&request, &callback, BoundNetLog());
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+
+ rv = callback.WaitForResult();
+ EXPECT_EQ(OK, rv);
+}
+
TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) {
SessionDependencies session_deps;
scoped_ptr<HttpTransaction> trans(
diff --git a/net/http/http_proxy_client_socket.cc b/net/http/http_proxy_client_socket.cc
index aa58cfb..78d470b 100644
--- a/net/http/http_proxy_client_socket.cc
+++ b/net/http/http_proxy_client_socket.cc
@@ -51,7 +51,8 @@ void BuildTunnelRequest(const HttpRequestInfo* request_info,
HttpProxyClientSocket::HttpProxyClientSocket(
ClientSocketHandle* transport_socket, const GURL& request_url,
- const HostPortPair& endpoint, const HostPortPair& proxy_server,
+ const std::string& user_agent, const HostPortPair& endpoint,
+ const HostPortPair& proxy_server,
const scoped_refptr<HttpNetworkSession>& session, bool tunnel)
: ALLOW_THIS_IN_INITIALIZER_LIST(
io_callback_(this, &HttpProxyClientSocket::OnIOComplete)),
@@ -68,6 +69,9 @@ HttpProxyClientSocket::HttpProxyClientSocket(
// Synthesize the bits of a request that we actually use.
request_.url = request_url;
request_.method = "GET";
+ if (!user_agent.empty())
+ request_.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent,
+ user_agent);
}
HttpProxyClientSocket::~HttpProxyClientSocket() {
diff --git a/net/http/http_proxy_client_socket.h b/net/http/http_proxy_client_socket.h
index 71945da..41bb50e 100644
--- a/net/http/http_proxy_client_socket.h
+++ b/net/http/http_proxy_client_socket.h
@@ -34,7 +34,9 @@ class HttpProxyClientSocket : public ClientSocket {
// by the time Connect() is called. If tunnel is true then on Connect()
// this socket will establish an Http tunnel.
HttpProxyClientSocket(ClientSocketHandle* transport_socket,
- const GURL& request_url, const HostPortPair& endpoint,
+ const GURL& request_url,
+ const std::string& user_agent,
+ const HostPortPair& endpoint,
const HostPortPair& proxy_server,
const scoped_refptr<HttpNetworkSession>& session,
bool tunnel);
diff --git a/net/http/http_proxy_client_socket_pool.cc b/net/http/http_proxy_client_socket_pool.cc
index dd06a78..ef2a640 100644
--- a/net/http/http_proxy_client_socket_pool.cc
+++ b/net/http/http_proxy_client_socket_pool.cc
@@ -19,11 +19,13 @@ namespace net {
HttpProxySocketParams::HttpProxySocketParams(
const scoped_refptr<TCPSocketParams>& proxy_server,
const GURL& request_url,
+ const std::string& user_agent,
HostPortPair endpoint,
scoped_refptr<HttpNetworkSession> session,
bool tunnel)
: tcp_params_(proxy_server),
request_url_(request_url),
+ user_agent_(user_agent),
endpoint_(endpoint),
session_(tunnel ? session : NULL),
tunnel_(tunnel) {
@@ -143,6 +145,7 @@ int HttpProxyConnectJob::DoHttpProxyConnect() {
// Add a HttpProxy connection on top of the tcp socket.
socket_.reset(new HttpProxyClientSocket(tcp_socket_handle_.release(),
params_->request_url(),
+ params_->user_agent(),
params_->endpoint(),
proxy_server,
params_->session(),
diff --git a/net/http/http_proxy_client_socket_pool.h b/net/http/http_proxy_client_socket_pool.h
index 03b842d..2a18086 100644
--- a/net/http/http_proxy_client_socket_pool.h
+++ b/net/http/http_proxy_client_socket_pool.h
@@ -31,7 +31,9 @@ class TCPSocketParams;
class HttpProxySocketParams : public base::RefCounted<HttpProxySocketParams> {
public:
HttpProxySocketParams(const scoped_refptr<TCPSocketParams>& proxy_server,
- const GURL& request_url, HostPortPair endpoint,
+ const GURL& request_url,
+ const std::string& user_agent,
+ HostPortPair endpoint,
scoped_refptr<HttpNetworkSession> session,
bool tunnel);
@@ -39,6 +41,7 @@ class HttpProxySocketParams : public base::RefCounted<HttpProxySocketParams> {
return tcp_params_;
}
const GURL& request_url() const { return request_url_; }
+ const std::string& user_agent() const { return user_agent_; }
const HostPortPair& endpoint() const { return endpoint_; }
const scoped_refptr<HttpNetworkSession>& session() {
return session_;
@@ -51,6 +54,7 @@ class HttpProxySocketParams : public base::RefCounted<HttpProxySocketParams> {
const scoped_refptr<TCPSocketParams> tcp_params_;
const GURL request_url_;
+ const std::string user_agent_;
const HostPortPair endpoint_;
const scoped_refptr<HttpNetworkSession> session_;
const bool tunnel_;
diff --git a/net/http/http_proxy_client_socket_pool_unittest.cc b/net/http/http_proxy_client_socket_pool_unittest.cc
index 3e06c3b..1f85ff2 100644
--- a/net/http/http_proxy_client_socket_pool_unittest.cc
+++ b/net/http/http_proxy_client_socket_pool_unittest.cc
@@ -46,10 +46,10 @@ class HttpProxyClientSocketPoolTest : public ClientSocketPoolTest {
NULL,
NULL)),
notunnel_socket_params_(new HttpProxySocketParams(
- ignored_tcp_socket_params_, GURL("http://host"),
+ ignored_tcp_socket_params_, GURL("http://host"), "",
HostPortPair("host", 80), NULL, false)),
tunnel_socket_params_(new HttpProxySocketParams(
- ignored_tcp_socket_params_, GURL("http://host"),
+ ignored_tcp_socket_params_, GURL("http://host"), "",
HostPortPair("host", 80), session_, true)),
http_proxy_histograms_(
new ClientSocketPoolHistograms("HttpProxyUnitTest")),