summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-25 00:15:32 +0000
committerrch@chromium.org <rch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-25 00:15:32 +0000
commitc0fe941d06a1a4f718c48c1fa6e5b8fb4406fa67 (patch)
tree1104d89c26f14d27f49ba05f091eddab3ae713d9
parentdea048aea15816f6d719a2fa723c7fdf441700c0 (diff)
downloadchromium_src-c0fe941d06a1a4f718c48c1fa6e5b8fb4406fa67.zip
chromium_src-c0fe941d06a1a4f718c48c1fa6e5b8fb4406fa67.tar.gz
chromium_src-c0fe941d06a1a4f718c48c1fa6e5b8fb4406fa67.tar.bz2
Minor refactor of ProxyClientSocket.
Adds GetAuthController and RestartWithAuth from Http/Spdy ProxyClientSocket. BUG=115659 Review URL: http://codereview.chromium.org/9442020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123600 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/base/net_error_list.h3
-rw-r--r--net/http/http_proxy_client_socket.cc30
-rw-r--r--net/http/http_proxy_client_socket.h26
-rw-r--r--net/http/http_proxy_client_socket_pool_unittest.cc2
-rw-r--r--net/http/http_proxy_utils.h28
-rw-r--r--net/http/http_stream_factory_impl_job.cc22
-rw-r--r--net/http/proxy_client_socket.cc (renamed from net/http/http_proxy_utils.cc)23
-rw-r--r--net/http/proxy_client_socket.h42
-rw-r--r--net/net.gyp3
-rw-r--r--net/spdy/spdy_proxy_client_socket.cc29
-rw-r--r--net/spdy/spdy_proxy_client_socket.h15
11 files changed, 133 insertions, 90 deletions
diff --git a/net/base/net_error_list.h b/net/base/net_error_list.h
index 750f9ad..df7975f 100644
--- a/net/base/net_error_list.h
+++ b/net/base/net_error_list.h
@@ -279,6 +279,9 @@ NET_ERROR(CLIENT_AUTH_CERT_TYPE_UNSUPPORTED, -151)
// first was still being generated.
NET_ERROR(ORIGIN_BOUND_CERT_GENERATION_TYPE_MISMATCH, -152)
+// The proxy does not support restarting a request on the existing connection.
+NET_ERROR(NO_KEEP_ALIVE_ON_AUTH_RESTART, -153)
+
// Certificate error codes
//
// The values of certificate error codes must be consecutive.
diff --git a/net/http/http_proxy_client_socket.cc b/net/http/http_proxy_client_socket.cc
index 8e6631a..1a2bac5 100644
--- a/net/http/http_proxy_client_socket.cc
+++ b/net/http/http_proxy_client_socket.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -17,7 +17,6 @@
#include "net/http/http_basic_stream.h"
#include "net/http/http_net_log_params.h"
#include "net/http/http_network_session.h"
-#include "net/http/http_proxy_utils.h"
#include "net/http/http_request_info.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_stream_parser.h"
@@ -84,6 +83,20 @@ int HttpProxyClientSocket::RestartWithAuth(const CompletionCallback& callback) {
return rv;
}
+const scoped_refptr<HttpAuthController>&
+HttpProxyClientSocket::GetAuthController() const {
+ return auth_;
+}
+
+bool HttpProxyClientSocket::IsUsingSpdy() const {
+ return using_spdy_;
+}
+
+SSLClientSocket::NextProto
+HttpProxyClientSocket::GetProtocolNegotiated() const {
+ return protocol_negotiated_;
+}
+
const HttpResponseInfo* HttpProxyClientSocket::GetConnectResponseInfo() const {
return response_.headers ? &response_ : NULL;
}
@@ -274,17 +287,6 @@ int HttpProxyClientSocket::DidDrainBodyForAuthRestart(bool keep_alive) {
return OK;
}
-int HttpProxyClientSocket::HandleAuthChallenge() {
- DCHECK(response_.headers);
-
- int rv = auth_->HandleAuthChallenge(response_.headers, false, true, net_log_);
- response_.auth_challenge = auth_->auth_info();
- if (rv == OK)
- return ERR_PROXY_AUTH_REQUESTED;
-
- return rv;
-}
-
void HttpProxyClientSocket::LogBlockedTunnelResponse(int response_code) const {
LOG(WARNING) << "Blocked proxy response with status " << response_code
<< " to CONNECT request for "
@@ -459,7 +461,7 @@ int HttpProxyClientSocket::DoReadHeadersComplete(int result) {
// authentication code is smart enough to avoid being tricked by an
// active network attacker.
// The next state is intentionally not set as it should be STATE_NONE;
- return HandleAuthChallenge();
+ return HandleProxyAuthChallenge(auth_, &response_, net_log_);
default:
if (is_https_proxy_)
diff --git a/net/http/http_proxy_client_socket.h b/net/http/http_proxy_client_socket.h
index e4b1844..db6f7e0 100644
--- a/net/http/http_proxy_client_socket.h
+++ b/net/http/http_proxy_client_socket.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -52,26 +52,14 @@ class HttpProxyClientSocket : public ProxyClientSocket {
// On destruction Disconnect() is called.
virtual ~HttpProxyClientSocket();
- // If Connect (or its callback) returns PROXY_AUTH_REQUESTED, then
- // credentials should be added to the HttpAuthController before calling
- // RestartWithAuth.
- int RestartWithAuth(const CompletionCallback& callback);
-
- const scoped_refptr<HttpAuthController>& auth_controller() {
- return auth_;
- }
-
- bool using_spdy() {
- return using_spdy_;
- }
-
- SSLClientSocket::NextProto protocol_negotiated() {
- return protocol_negotiated_;
- }
-
// ProxyClientSocket implementation.
virtual const HttpResponseInfo* GetConnectResponseInfo() const OVERRIDE;
virtual HttpStream* CreateConnectResponseStream() OVERRIDE;
+ virtual int RestartWithAuth(const CompletionCallback& callback) OVERRIDE;
+ virtual const scoped_refptr<HttpAuthController>& GetAuthController() const
+ OVERRIDE;
+ virtual bool IsUsingSpdy() const OVERRIDE;
+ virtual SSLClientSocket::NextProto GetProtocolNegotiated() const OVERRIDE;
// StreamSocket implementation.
virtual int Connect(const CompletionCallback& callback) OVERRIDE;
@@ -122,8 +110,6 @@ class HttpProxyClientSocket : public ProxyClientSocket {
int PrepareForAuthRestart();
int DidDrainBodyForAuthRestart(bool keep_alive);
- int HandleAuthChallenge();
-
void LogBlockedTunnelResponse(int response_code) const;
void DoCallback(int result);
diff --git a/net/http/http_proxy_client_socket_pool_unittest.cc b/net/http/http_proxy_client_socket_pool_unittest.cc
index 77882f4..0e99ac2 100644
--- a/net/http/http_proxy_client_socket_pool_unittest.cc
+++ b/net/http/http_proxy_client_socket_pool_unittest.cc
@@ -286,7 +286,7 @@ TEST_P(HttpProxyClientSocketPoolTest, NeedAuth) {
HttpProxyClientSocket* tunnel_socket =
static_cast<HttpProxyClientSocket*>(handle_.socket());
EXPECT_FALSE(tunnel_socket->IsConnected());
- EXPECT_FALSE(tunnel_socket->using_spdy());
+ EXPECT_FALSE(tunnel_socket->IsUsingSpdy());
} else {
// Proxy auth is not really implemented for SPDY yet
EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
diff --git a/net/http/http_proxy_utils.h b/net/http/http_proxy_utils.h
deleted file mode 100644
index b93d034..0000000
--- a/net/http/http_proxy_utils.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef NET_HTTP_HTTP_PROXY_UTILS_H_
-#define NET_HTTP_HTTP_PROXY_UTILS_H_
-#pragma once
-
-#include <string>
-
-namespace net {
-
-struct HttpRequestInfo;
-class HttpRequestHeaders;
-class HostPortPair;
-
-// The HTTP CONNECT method for establishing a tunnel connection is documented
-// in draft-luotonen-web-proxy-tunneling-01.txt and RFC 2817, Sections 5.2 and
-// 5.3.
-void BuildTunnelRequest(const HttpRequestInfo& request_info,
- const HttpRequestHeaders& auth_headers,
- const HostPortPair& endpoint,
- std::string* request_line,
- HttpRequestHeaders* request_headers);
-
-} // namespace net
-
-#endif // NET_HTTP_HTTP_PROXY_UTILS_H_
diff --git a/net/http/http_stream_factory_impl_job.cc b/net/http/http_stream_factory_impl_job.cc
index 2bdc55e0..0647732 100644
--- a/net/http/http_stream_factory_impl_job.cc
+++ b/net/http/http_stream_factory_impl_job.cc
@@ -419,10 +419,10 @@ int HttpStreamFactoryImpl::Job::RunLoop(int result) {
DCHECK(connection_->socket());
DCHECK(establishing_tunnel_);
- HttpProxyClientSocket* http_proxy_socket =
- static_cast<HttpProxyClientSocket*>(connection_->socket());
+ ProxyClientSocket* proxy_socket =
+ static_cast<ProxyClientSocket*>(connection_->socket());
const HttpResponseInfo* tunnel_auth_response =
- http_proxy_socket->GetConnectResponseInfo();
+ proxy_socket->GetConnectResponseInfo();
next_state_ = STATE_WAITING_USER_ACTION;
MessageLoop::current()->PostTask(
@@ -431,7 +431,7 @@ int HttpStreamFactoryImpl::Job::RunLoop(int result) {
&HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback,
ptr_factory_.GetWeakPtr(),
*tunnel_auth_response,
- http_proxy_socket->auth_controller()));
+ proxy_socket->GetAuthController()));
}
return ERR_IO_PENDING;
@@ -788,11 +788,11 @@ int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) {
SwitchToSpdyMode();
} else if (proxy_info_.is_https() && connection_->socket() &&
result == OK) {
- HttpProxyClientSocket* proxy_socket =
- static_cast<HttpProxyClientSocket*>(connection_->socket());
- if (proxy_socket->using_spdy()) {
+ ProxyClientSocket* proxy_socket =
+ static_cast<ProxyClientSocket*>(connection_->socket());
+ if (proxy_socket->IsUsingSpdy()) {
was_npn_negotiated_ = true;
- protocol_negotiated_ = proxy_socket->protocol_negotiated();
+ protocol_negotiated_ = proxy_socket->GetProtocolNegotiated();
SwitchToSpdyMode();
}
}
@@ -970,9 +970,9 @@ int HttpStreamFactoryImpl::Job::DoCreateStreamComplete(int result) {
int HttpStreamFactoryImpl::Job::DoRestartTunnelAuth() {
next_state_ = STATE_RESTART_TUNNEL_AUTH_COMPLETE;
- HttpProxyClientSocket* http_proxy_socket =
- static_cast<HttpProxyClientSocket*>(connection_->socket());
- return http_proxy_socket->RestartWithAuth(io_callback_);
+ ProxyClientSocket* proxy_socket =
+ static_cast<ProxyClientSocket*>(connection_->socket());
+ return proxy_socket->RestartWithAuth(io_callback_);
}
int HttpStreamFactoryImpl::Job::DoRestartTunnelAuthComplete(int result) {
diff --git a/net/http/http_proxy_utils.cc b/net/http/proxy_client_socket.cc
index 7086bda..fb0a5a2 100644
--- a/net/http/http_proxy_utils.cc
+++ b/net/http/proxy_client_socket.cc
@@ -1,18 +1,23 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "net/http/http_proxy_utils.h"
+#include "net/http/proxy_client_socket.h"
#include "base/stringprintf.h"
#include "googleurl/src/gurl.h"
#include "net/base/host_port_pair.h"
+#include "net/base/net_errors.h"
#include "net/base/net_util.h"
+#include "net/http/http_auth_controller.h"
#include "net/http/http_request_info.h"
+#include "net/http/http_response_headers.h"
+#include "net/http/http_response_info.h"
namespace net {
-void BuildTunnelRequest(
+// static
+void ProxyClientSocket::BuildTunnelRequest(
const HttpRequestInfo& request_info,
const HttpRequestHeaders& auth_headers,
const HostPortPair& endpoint,
@@ -36,4 +41,16 @@ void BuildTunnelRequest(
request_headers->MergeFrom(auth_headers);
}
+// static
+int ProxyClientSocket::HandleProxyAuthChallenge(HttpAuthController* auth,
+ HttpResponseInfo* response,
+ const BoundNetLog& net_log) {
+ DCHECK(response->headers);
+ int rv = auth->HandleAuthChallenge(response->headers, false, true, net_log);
+ response->auth_challenge = auth->auth_info();
+ if (rv == OK)
+ return ERR_PROXY_AUTH_REQUESTED;
+ return rv;
+}
+
} // namespace net
diff --git a/net/http/proxy_client_socket.h b/net/http/proxy_client_socket.h
index 451e098..f22dcbe 100644
--- a/net/http/proxy_client_socket.h
+++ b/net/http/proxy_client_socket.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,12 +6,20 @@
#define NET_HTTP_PROXY_CLIENT_SOCKET_H_
#pragma once
+#include <string>
+
+#include "net/socket/ssl_client_socket.h"
#include "net/socket/stream_socket.h"
namespace net {
+class HostPortPair;
+class HttpAuthController;
class HttpStream;
class HttpResponseInfo;
+class HttpRequestHeaders;
+struct HttpRequestInfo;
+class HttpAuthController;
class NET_EXPORT_PRIVATE ProxyClientSocket : public StreamSocket {
public:
@@ -26,6 +34,38 @@ class NET_EXPORT_PRIVATE ProxyClientSocket : public StreamSocket {
// which can be used to read the response body.
virtual HttpStream* CreateConnectResponseStream() = 0;
+ // Returns the HttpAuthController which can be used
+ // to interact with an HTTP Proxy Authorization Required (407) request.
+ virtual const scoped_refptr<HttpAuthController>& GetAuthController() const
+ = 0;
+
+ // If Connect (or its callback) returns PROXY_AUTH_REQUESTED, then
+ // credentials should be added to the HttpAuthController before calling
+ // RestartWithAuth.
+ virtual int RestartWithAuth(const CompletionCallback& callback) = 0;
+
+ // Returns true of the connection to the proxy is using SPDY.
+ virtual bool IsUsingSpdy() const = 0;
+
+ // Returns the protocol negotiated with the proxy.
+ virtual SSLClientSocket::NextProto GetProtocolNegotiated() const = 0;
+
+ protected:
+ // The HTTP CONNECT method for establishing a tunnel connection is documented
+ // in draft-luotonen-web-proxy-tunneling-01.txt and RFC 2817, Sections 5.2
+ // and 5.3.
+ static void BuildTunnelRequest(const HttpRequestInfo& request_info,
+ const HttpRequestHeaders& auth_headers,
+ const HostPortPair& endpoint,
+ std::string* request_line,
+ HttpRequestHeaders* request_headers);
+
+ // When an auth challenge (407 response) is received during tunnel
+ // construction/ this method should be called.
+ static int HandleProxyAuthChallenge(HttpAuthController* auth,
+ HttpResponseInfo* response,
+ const BoundNetLog& net_log);
+
private:
DISALLOW_COPY_AND_ASSIGN(ProxyClientSocket);
};
diff --git a/net/net.gyp b/net/net.gyp
index ef5e249..702e8c6 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -457,8 +457,6 @@
'http/http_proxy_client_socket.h',
'http/http_proxy_client_socket_pool.cc',
'http/http_proxy_client_socket_pool.h',
- 'http/http_proxy_utils.cc',
- 'http/http_proxy_utils.h',
'http/http_request_headers.cc',
'http/http_request_headers.h',
'http/http_request_info.cc',
@@ -497,6 +495,7 @@
'http/partial_data.cc',
'http/partial_data.h',
'http/proxy_client_socket.h',
+ 'http/proxy_client_socket.cc',
'http/url_security_manager.cc',
'http/url_security_manager.h',
'http/url_security_manager_posix.cc',
diff --git a/net/spdy/spdy_proxy_client_socket.cc b/net/spdy/spdy_proxy_client_socket.cc
index a6c50e9..43195b8 100644
--- a/net/spdy/spdy_proxy_client_socket.cc
+++ b/net/spdy/spdy_proxy_client_socket.cc
@@ -17,7 +17,6 @@
#include "net/http/http_auth_cache.h"
#include "net/http/http_auth_handler_factory.h"
#include "net/http/http_net_log_params.h"
-#include "net/http/http_proxy_utils.h"
#include "net/http/http_response_headers.h"
#include "net/spdy/spdy_http_utils.h"
@@ -61,6 +60,34 @@ const HttpResponseInfo* SpdyProxyClientSocket::GetConnectResponseInfo() const {
return response_.headers ? &response_ : NULL;
}
+const scoped_refptr<HttpAuthController>&
+SpdyProxyClientSocket::GetAuthController() const {
+ return auth_;
+}
+
+int SpdyProxyClientSocket::RestartWithAuth(const CompletionCallback& callback) {
+ // A SPDY Stream can only handle a single request, so the underlying
+ // stream may not be reused and a new SpdyProxyClientSocket must be
+ // created (possibly on top of the same SPDY Session).
+ next_state_ = STATE_DISCONNECTED;
+ return ERR_NO_KEEP_ALIVE_ON_AUTH_RESTART;
+}
+
+bool SpdyProxyClientSocket::IsUsingSpdy() const {
+ return true;
+}
+
+SSLClientSocket::NextProto
+SpdyProxyClientSocket::GetProtocolNegotiated() const {
+ // Save the negotiated protocol
+ SSLInfo ssl_info;
+ bool was_npn_negotiated;
+ SSLClientSocket::NextProto protocol_negotiated;
+ spdy_stream_->GetSSLInfo(&ssl_info, &was_npn_negotiated,
+ &protocol_negotiated);
+ return protocol_negotiated;
+}
+
HttpStream* SpdyProxyClientSocket::CreateConnectResponseStream() {
DCHECK(response_stream_.get());
return response_stream_.release();
diff --git a/net/spdy/spdy_proxy_client_socket.h b/net/spdy/spdy_proxy_client_socket.h
index b969499..e7fd2c3 100644
--- a/net/spdy/spdy_proxy_client_socket.h
+++ b/net/spdy/spdy_proxy_client_socket.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -54,17 +54,14 @@ class NET_EXPORT_PRIVATE SpdyProxyClientSocket : public ProxyClientSocket,
// On destruction Disconnect() is called.
virtual ~SpdyProxyClientSocket();
- const scoped_refptr<HttpAuthController>& auth_controller() {
- return auth_;
- }
-
// ProxyClientSocket methods:
virtual const HttpResponseInfo* GetConnectResponseInfo() const OVERRIDE;
-
- // In the event of a non-200 response to the CONNECT request, this
- // method may be called to return an HttpStream in order to read
- // the response body.
virtual HttpStream* CreateConnectResponseStream() OVERRIDE;
+ virtual const scoped_refptr<HttpAuthController>& GetAuthController() const
+ OVERRIDE;
+ virtual int RestartWithAuth(const CompletionCallback& callback) OVERRIDE;
+ virtual bool IsUsingSpdy() const OVERRIDE;
+ virtual SSLClientSocket::NextProto GetProtocolNegotiated() const OVERRIDE;
// StreamSocket implementation.
virtual int Connect(const CompletionCallback& callback) OVERRIDE;