Proxy Delegate Add CONNECT Tunnel headers for H2 and QUIC
OnBeforeTunnelRequest and OnTunnelHeadersReceived both drop their
H1 qualifiers and are now called during H2 and QUIC CONNECT proxy
tunnel setup.
Bug: 926427
Change-Id: Ia512f01bc592bfa5ca196d6c2aa0b8b5dcac479b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2099294
Commit-Queue: Robert Ogden <[email protected]>
Reviewed-by: Tarun Bansal <[email protected]>
Reviewed-by: Matt Menke <[email protected]>
Cr-Commit-Position: refs/heads/master@{#751104}
diff --git a/net/spdy/spdy_proxy_client_socket.cc b/net/spdy/spdy_proxy_client_socket.cc
index 2156b4b..c7621eb 100644
--- a/net/spdy/spdy_proxy_client_socket.cc
+++ b/net/spdy/spdy_proxy_client_socket.cc
@@ -18,6 +18,7 @@
#include "base/values.h"
#include "net/base/auth.h"
#include "net/base/io_buffer.h"
+#include "net/base/proxy_delegate.h"
#include "net/http/http_auth_cache.h"
#include "net/http/http_auth_handler_factory.h"
#include "net/http/http_log_util.h"
@@ -33,14 +34,18 @@
SpdyProxyClientSocket::SpdyProxyClientSocket(
const base::WeakPtr<SpdyStream>& spdy_stream,
+ const ProxyServer& proxy_server,
const std::string& user_agent,
const HostPortPair& endpoint,
const NetLogWithSource& source_net_log,
- HttpAuthController* auth_controller)
+ HttpAuthController* auth_controller,
+ ProxyDelegate* proxy_delegate)
: next_state_(STATE_DISCONNECTED),
spdy_stream_(spdy_stream),
endpoint_(endpoint),
auth_(auth_controller),
+ proxy_server_(proxy_server),
+ proxy_delegate_(proxy_delegate),
user_agent_(user_agent),
user_buffer_len_(0),
write_buffer_len_(0),
@@ -363,6 +368,13 @@
auth_->AddAuthorizationHeader(&authorization_headers);
}
+ if (proxy_delegate_) {
+ HttpRequestHeaders proxy_delegate_headers;
+ proxy_delegate_->OnBeforeTunnelRequest(proxy_server_,
+ &proxy_delegate_headers);
+ request_.extra_headers.MergeFrom(proxy_delegate_headers);
+ }
+
std::string request_line;
BuildTunnelRequest(endpoint_, authorization_headers, user_agent_,
&request_line, &request_.extra_headers);
@@ -402,6 +414,15 @@
net_log_, NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
response_.headers.get());
+ if (proxy_delegate_) {
+ int rv = proxy_delegate_->OnTunnelHeadersReceived(proxy_server_,
+ *response_.headers);
+ if (rv != OK) {
+ DCHECK_NE(ERR_IO_PENDING, rv);
+ return rv;
+ }
+ }
+
switch (response_.headers->response_code()) {
case 200: // OK
next_state_ = STATE_OPEN;
diff --git a/net/spdy/spdy_proxy_client_socket.h b/net/spdy/spdy_proxy_client_socket.h
index 744a2b8..4ad7a96 100644
--- a/net/spdy/spdy_proxy_client_socket.h
+++ b/net/spdy/spdy_proxy_client_socket.h
@@ -18,6 +18,7 @@
#include "net/base/completion_once_callback.h"
#include "net/base/host_port_pair.h"
#include "net/base/net_export.h"
+#include "net/base/proxy_server.h"
#include "net/http/http_auth_controller.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_request_info.h"
@@ -35,6 +36,7 @@
namespace net {
class IOBuffer;
+class ProxyDelegate;
class SpdyStream;
class NET_EXPORT_PRIVATE SpdyProxyClientSocket : public ProxyClientSocket,
@@ -45,10 +47,12 @@
// data read/written to the socket will be transferred in data frames. This
// object will set itself as |spdy_stream|'s delegate.
SpdyProxyClientSocket(const base::WeakPtr<SpdyStream>& spdy_stream,
+ const ProxyServer& proxy_server,
const std::string& user_agent,
const HostPortPair& endpoint,
const NetLogWithSource& source_net_log,
- HttpAuthController* auth_controller);
+ HttpAuthController* auth_controller,
+ ProxyDelegate* proxy_delegate);
// On destruction Disconnect() is called.
~SpdyProxyClientSocket() override;
@@ -155,6 +159,11 @@
const HostPortPair endpoint_;
scoped_refptr<HttpAuthController> auth_;
+ const ProxyServer proxy_server_;
+
+ // This delegate must outlive this proxy client socket.
+ ProxyDelegate* const proxy_delegate_;
+
std::string user_agent_;
// We buffer the response body as it arrives asynchronously from the stream.
diff --git a/net/spdy/spdy_proxy_client_socket_unittest.cc b/net/spdy/spdy_proxy_client_socket_unittest.cc
index 6c107dc..adad830 100644
--- a/net/spdy/spdy_proxy_client_socket_unittest.cc
+++ b/net/spdy/spdy_proxy_client_socket_unittest.cc
@@ -14,6 +14,7 @@
#include "base/strings/utf_string_conversions.h"
#include "net/base/address_list.h"
#include "net/base/load_timing_info.h"
+#include "net/base/proxy_server.h"
#include "net/base/test_completion_callback.h"
#include "net/base/winsock_init.h"
#include "net/dns/mock_host_resolver.h"
@@ -265,11 +266,14 @@
// Create the SpdyProxyClientSocket.
sock_ = std::make_unique<SpdyProxyClientSocket>(
- spdy_stream, user_agent_, endpoint_host_port_pair_, net_log_.bound(),
+ spdy_stream, ProxyServer(ProxyServer::SCHEME_HTTPS, proxy_host_port_),
+ user_agent_, endpoint_host_port_pair_, net_log_.bound(),
new HttpAuthController(
HttpAuth::AUTH_PROXY, GURL("https://" + proxy_host_port_.ToString()),
NetworkIsolationKey(), session_->http_auth_cache(),
- session_->http_auth_handler_factory(), session_->host_resolver()));
+ session_->http_auth_handler_factory(), session_->host_resolver()),
+ // Testing with the proxy delegate is in HttpProxyConnectJobTest.
+ nullptr);
}
scoped_refptr<IOBufferWithSize> SpdyProxyClientSocketTest::CreateBuffer(