[email protected] | e92fa7e1 | 2012-02-16 23:31:22 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 5 | #include "net/spdy/spdy_proxy_client_socket.h" |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 6 | |
| 7 | #include <algorithm> // min |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 8 | #include <utility> |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 9 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10 | #include "base/bind.h" |
[email protected] | aa19cfc | 2013-05-23 16:41:38 | [diff] [blame] | 11 | #include "base/callback_helpers.h" |
Hans Wennborg | 0924470b | 2020-04-27 21:08:05 | [diff] [blame] | 12 | #include "base/check_op.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 13 | #include "base/location.h" |
Hans Wennborg | 0924470b | 2020-04-27 21:08:05 | [diff] [blame] | 14 | #include "base/notreached.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 15 | #include "base/single_thread_task_runner.h" |
[email protected] | fc9be580 | 2013-06-11 10:56:51 | [diff] [blame] | 16 | #include "base/strings/string_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 17 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 18 | #include "base/values.h" |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 19 | #include "net/base/auth.h" |
| 20 | #include "net/base/io_buffer.h" |
Robert Ogden | 78d4f9eb | 2020-03-17 20:56:38 | [diff] [blame] | 21 | #include "net/base/proxy_delegate.h" |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 22 | #include "net/http/http_auth_cache.h" |
| 23 | #include "net/http/http_auth_handler_factory.h" |
Eric Roman | 06bd974 | 2019-07-13 15:19:13 | [diff] [blame] | 24 | #include "net/http/http_log_util.h" |
rch | c5c07de | 2015-04-08 07:28:18 | [diff] [blame] | 25 | #include "net/http/http_request_info.h" |
[email protected] | b104b50 | 2010-10-18 20:21:31 | [diff] [blame] | 26 | #include "net/http/http_response_headers.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 27 | #include "net/log/net_log_event_type.h" |
| 28 | #include "net/log/net_log_source_type.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 29 | #include "net/spdy/spdy_http_utils.h" |
[email protected] | a2b2cfc | 2017-12-06 09:06:08 | [diff] [blame] | 30 | #include "net/traffic_annotation/network_traffic_annotation.h" |
[email protected] | f89276a7 | 2013-07-12 06:41:54 | [diff] [blame] | 31 | #include "url/gurl.h" |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 32 | |
| 33 | namespace net { |
| 34 | |
| 35 | SpdyProxyClientSocket::SpdyProxyClientSocket( |
[email protected] | d26ff35 | 2013-05-13 08:48:28 | [diff] [blame] | 36 | const base::WeakPtr<SpdyStream>& spdy_stream, |
Robert Ogden | 78d4f9eb | 2020-03-17 20:56:38 | [diff] [blame] | 37 | const ProxyServer& proxy_server, |
Bence Béky | 4e83f49 | 2018-05-13 23:14:25 | [diff] [blame] | 38 | const std::string& user_agent, |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 39 | const HostPortPair& endpoint, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 40 | const NetLogWithSource& source_net_log, |
Robert Ogden | 78d4f9eb | 2020-03-17 20:56:38 | [diff] [blame] | 41 | HttpAuthController* auth_controller, |
| 42 | ProxyDelegate* proxy_delegate) |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 43 | : next_state_(STATE_DISCONNECTED), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 44 | spdy_stream_(spdy_stream), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 45 | endpoint_(endpoint), |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 46 | auth_(auth_controller), |
Robert Ogden | 78d4f9eb | 2020-03-17 20:56:38 | [diff] [blame] | 47 | proxy_server_(proxy_server), |
| 48 | proxy_delegate_(proxy_delegate), |
rch | ecd3c55 | 2015-04-07 20:53:54 | [diff] [blame] | 49 | user_agent_(user_agent), |
[email protected] | ca690b0 | 2013-04-17 10:38:43 | [diff] [blame] | 50 | user_buffer_len_(0), |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 51 | write_buffer_len_(0), |
[email protected] | 57d2dfa | 2013-06-24 06:04:12 | [diff] [blame] | 52 | was_ever_used_(false), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 53 | net_log_(NetLogWithSource::Make(spdy_stream->net_log().net_log(), |
| 54 | NetLogSourceType::PROXY_CLIENT_SOCKET)), |
Jeremy Roman | d54000b2 | 2019-07-08 18:40:16 | [diff] [blame] | 55 | source_dependency_(source_net_log.source()) { |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 56 | request_.method = "CONNECT"; |
rch | ecd3c55 | 2015-04-07 20:53:54 | [diff] [blame] | 57 | request_.url = GURL("https://" + endpoint.ToString()); |
Eric Roman | 06bd974 | 2019-07-13 15:19:13 | [diff] [blame] | 58 | net_log_.BeginEventReferencingSource(NetLogEventType::SOCKET_ALIVE, |
| 59 | source_net_log.source()); |
| 60 | net_log_.AddEventReferencingSource( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 61 | NetLogEventType::HTTP2_PROXY_CLIENT_SESSION, |
Eric Roman | 06bd974 | 2019-07-13 15:19:13 | [diff] [blame] | 62 | spdy_stream->net_log().source()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 63 | |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 64 | spdy_stream_->SetDelegate(this); |
| 65 | was_ever_used_ = spdy_stream_->WasEverUsed(); |
| 66 | } |
| 67 | |
| 68 | SpdyProxyClientSocket::~SpdyProxyClientSocket() { |
| 69 | Disconnect(); |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 70 | net_log_.EndEvent(NetLogEventType::SOCKET_ALIVE); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 71 | } |
| 72 | |
[email protected] | be1a48b | 2011-01-20 00:12:13 | [diff] [blame] | 73 | const HttpResponseInfo* SpdyProxyClientSocket::GetConnectResponseInfo() const { |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 74 | return response_.headers.get() ? &response_ : nullptr; |
[email protected] | be1a48b | 2011-01-20 00:12:13 | [diff] [blame] | 75 | } |
| 76 | |
[email protected] | c0fe941d | 2012-02-25 00:15:32 | [diff] [blame] | 77 | const scoped_refptr<HttpAuthController>& |
| 78 | SpdyProxyClientSocket::GetAuthController() const { |
| 79 | return auth_; |
| 80 | } |
| 81 | |
Bence Béky | 9983223 | 2018-02-11 04:21:00 | [diff] [blame] | 82 | int SpdyProxyClientSocket::RestartWithAuth(CompletionOnceCallback callback) { |
[email protected] | c0fe941d | 2012-02-25 00:15:32 | [diff] [blame] | 83 | // A SPDY Stream can only handle a single request, so the underlying |
| 84 | // stream may not be reused and a new SpdyProxyClientSocket must be |
| 85 | // created (possibly on top of the same SPDY Session). |
| 86 | next_state_ = STATE_DISCONNECTED; |
Matt Menke | ae2cbb8 | 2019-02-21 20:20:13 | [diff] [blame] | 87 | return ERR_UNABLE_TO_REUSE_CONNECTION_FOR_PROXY_AUTH; |
[email protected] | c0fe941d | 2012-02-25 00:15:32 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | bool SpdyProxyClientSocket::IsUsingSpdy() const { |
| 91 | return true; |
| 92 | } |
| 93 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 94 | NextProto SpdyProxyClientSocket::GetProxyNegotiatedProtocol() const { |
bnc | 4cb660c | 2016-08-11 19:43:12 | [diff] [blame] | 95 | return spdy_stream_->GetNegotiatedProtocol(); |
[email protected] | c0fe941d | 2012-02-25 00:15:32 | [diff] [blame] | 96 | } |
| 97 | |
Matt Menke | edaf3b8 | 2019-03-14 21:39:44 | [diff] [blame] | 98 | // Ignore priority changes, just use priority of initial request. Since multiple |
| 99 | // requests are pooled on the SpdyProxyClientSocket, reprioritization doesn't |
| 100 | // really work. |
| 101 | // |
| 102 | // TODO(mmenke): Use a single priority value for all SpdyProxyClientSockets, |
| 103 | // regardless of what priority they're created with. |
| 104 | void SpdyProxyClientSocket::SetStreamPriority(RequestPriority priority) {} |
Lily Chen | f11e129 | 2018-11-29 16:42:09 | [diff] [blame] | 105 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 106 | // Sends a HEADERS frame to the proxy with a CONNECT request |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 107 | // for the specified endpoint. Waits for the server to send back |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 108 | // a HEADERS frame. OK will be returned if the status is 200. |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 109 | // ERR_TUNNEL_CONNECTION_FAILED will be returned for any other status. |
| 110 | // In any of these cases, Read() may be called to retrieve the HTTP |
| 111 | // response body. Any other return values should be considered fatal. |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 112 | // TODO(rch): handle 407 proxy auth requested correctly, perhaps |
| 113 | // by creating a new stream for the subsequent request. |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 114 | // TODO(rch): create a more appropriate error code to disambiguate |
| 115 | // the HTTPS Proxy tunnel failure from an HTTP Proxy tunnel failure. |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 116 | int SpdyProxyClientSocket::Connect(CompletionOnceCallback callback) { |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 117 | DCHECK(read_callback_.is_null()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 118 | if (next_state_ == STATE_OPEN) |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 119 | return OK; |
| 120 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 121 | DCHECK_EQ(STATE_DISCONNECTED, next_state_); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 122 | next_state_ = STATE_GENERATE_AUTH_TOKEN; |
| 123 | |
| 124 | int rv = DoLoop(OK); |
| 125 | if (rv == ERR_IO_PENDING) |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 126 | read_callback_ = std::move(callback); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 127 | return rv; |
| 128 | } |
| 129 | |
| 130 | void SpdyProxyClientSocket::Disconnect() { |
[email protected] | ca690b0 | 2013-04-17 10:38:43 | [diff] [blame] | 131 | read_buffer_queue_.Clear(); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 132 | user_buffer_ = nullptr; |
[email protected] | ca690b0 | 2013-04-17 10:38:43 | [diff] [blame] | 133 | user_buffer_len_ = 0; |
[email protected] | dbf036f | 2011-12-06 23:33:24 | [diff] [blame] | 134 | read_callback_.Reset(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 135 | |
| 136 | write_buffer_len_ = 0; |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 137 | write_callback_.Reset(); |
[email protected] | 0a428c2 | 2014-06-14 02:26:37 | [diff] [blame] | 138 | write_callback_weak_factory_.InvalidateWeakPtrs(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 139 | |
| 140 | next_state_ = STATE_DISCONNECTED; |
| 141 | |
[email protected] | 11fbca0b | 2013-06-02 23:37:21 | [diff] [blame] | 142 | if (spdy_stream_.get()) { |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 143 | // This will cause OnClose to be invoked, which takes care of |
| 144 | // cleaning up all the internal state. |
Bence Béky | 6b9c135 | 2018-05-10 11:51:25 | [diff] [blame] | 145 | spdy_stream_->Cancel(ERR_ABORTED); |
[email protected] | 11fbca0b | 2013-06-02 23:37:21 | [diff] [blame] | 146 | DCHECK(!spdy_stream_.get()); |
[email protected] | f6a7829 | 2013-03-09 14:36:34 | [diff] [blame] | 147 | } |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | bool SpdyProxyClientSocket::IsConnected() const { |
[email protected] | 194c7a9 | 2011-12-03 04:54:18 | [diff] [blame] | 151 | return next_state_ == STATE_OPEN; |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | bool SpdyProxyClientSocket::IsConnectedAndIdle() const { |
[email protected] | ca690b0 | 2013-04-17 10:38:43 | [diff] [blame] | 155 | return IsConnected() && read_buffer_queue_.IsEmpty() && |
[email protected] | 5ff0ed3 | 2014-02-12 17:48:51 | [diff] [blame] | 156 | spdy_stream_->IsOpen(); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 157 | } |
| 158 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 159 | const NetLogWithSource& SpdyProxyClientSocket::NetLog() const { |
[email protected] | e4be2dd | 2010-12-14 00:44:39 | [diff] [blame] | 160 | return net_log_; |
| 161 | } |
| 162 | |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 163 | bool SpdyProxyClientSocket::WasEverUsed() const { |
[email protected] | 11fbca0b | 2013-06-02 23:37:21 | [diff] [blame] | 164 | return was_ever_used_ || (spdy_stream_.get() && spdy_stream_->WasEverUsed()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 165 | } |
| 166 | |
tfarina | 2846404c | 2016-12-25 14:31:37 | [diff] [blame] | 167 | bool SpdyProxyClientSocket::WasAlpnNegotiated() const { |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 168 | return false; |
| 169 | } |
| 170 | |
[email protected] | 33661e48 | 2012-04-03 16:16:26 | [diff] [blame] | 171 | NextProto SpdyProxyClientSocket::GetNegotiatedProtocol() const { |
| 172 | return kProtoUnknown; |
| 173 | } |
| 174 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 175 | bool SpdyProxyClientSocket::GetSSLInfo(SSLInfo* ssl_info) { |
bnc | 4cb660c | 2016-08-11 19:43:12 | [diff] [blame] | 176 | return spdy_stream_->GetSSLInfo(ssl_info); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 177 | } |
| 178 | |
ttuttle | 23fdb7b | 2015-05-15 01:28:03 | [diff] [blame] | 179 | void SpdyProxyClientSocket::GetConnectionAttempts( |
| 180 | ConnectionAttempts* out) const { |
| 181 | out->clear(); |
| 182 | } |
| 183 | |
tbansal | f82cc8e | 2015-10-14 20:05:49 | [diff] [blame] | 184 | int64_t SpdyProxyClientSocket::GetTotalReceivedBytes() const { |
| 185 | NOTIMPLEMENTED(); |
| 186 | return 0; |
| 187 | } |
| 188 | |
Paul Jensen | 0f49dec | 2017-12-12 23:39:58 | [diff] [blame] | 189 | void SpdyProxyClientSocket::ApplySocketTag(const SocketTag& tag) { |
Matt Menke | 5b7974fa | 2019-03-09 01:18:12 | [diff] [blame] | 190 | // In the case of a connection to the proxy using HTTP/2 or HTTP/3 where the |
| 191 | // underlying socket may multiplex multiple streams, applying this request's |
| 192 | // socket tag to the multiplexed session would incorrectly apply the socket |
| 193 | // tag to all mutliplexed streams. Fortunately socket tagging is only |
| 194 | // supported on Android without the data reduction proxy, so only simple HTTP |
| 195 | // proxies are supported, so proxies won't be using HTTP/2 or HTTP/3. Enforce |
| 196 | // that a specific (non-default) tag isn't being applied. |
| 197 | CHECK(tag == SocketTag()); |
Paul Jensen | 0f49dec | 2017-12-12 23:39:58 | [diff] [blame] | 198 | } |
| 199 | |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 200 | int SpdyProxyClientSocket::Read(IOBuffer* buf, |
| 201 | int buf_len, |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 202 | CompletionOnceCallback callback) { |
Helen Li | d714188 | 2018-08-22 21:41:17 | [diff] [blame] | 203 | int rv = ReadIfReady(buf, buf_len, std::move(callback)); |
| 204 | if (rv == ERR_IO_PENDING) { |
| 205 | user_buffer_ = buf; |
| 206 | user_buffer_len_ = static_cast<size_t>(buf_len); |
| 207 | } |
| 208 | return rv; |
| 209 | } |
| 210 | |
| 211 | int SpdyProxyClientSocket::ReadIfReady(IOBuffer* buf, |
| 212 | int buf_len, |
| 213 | CompletionOnceCallback callback) { |
| 214 | DCHECK(!read_callback_); |
| 215 | DCHECK(!user_buffer_); |
[email protected] | 3f55aa1 | 2011-12-07 02:03:33 | [diff] [blame] | 216 | |
| 217 | if (next_state_ == STATE_DISCONNECTED) |
| 218 | return ERR_SOCKET_NOT_CONNECTED; |
| 219 | |
[email protected] | ca690b0 | 2013-04-17 10:38:43 | [diff] [blame] | 220 | if (next_state_ == STATE_CLOSED && read_buffer_queue_.IsEmpty()) { |
[email protected] | 3f55aa1 | 2011-12-07 02:03:33 | [diff] [blame] | 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | DCHECK(next_state_ == STATE_OPEN || next_state_ == STATE_CLOSED); |
| 225 | DCHECK(buf); |
[email protected] | ca690b0 | 2013-04-17 10:38:43 | [diff] [blame] | 226 | size_t result = PopulateUserReadBuffer(buf->data(), buf_len); |
[email protected] | 3f55aa1 | 2011-12-07 02:03:33 | [diff] [blame] | 227 | if (result == 0) { |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 228 | read_callback_ = std::move(callback); |
[email protected] | 3f55aa1 | 2011-12-07 02:03:33 | [diff] [blame] | 229 | return ERR_IO_PENDING; |
| 230 | } |
[email protected] | 3f55aa1 | 2011-12-07 02:03:33 | [diff] [blame] | 231 | return result; |
| 232 | } |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 233 | |
Helen Li | d714188 | 2018-08-22 21:41:17 | [diff] [blame] | 234 | int SpdyProxyClientSocket::CancelReadIfReady() { |
| 235 | // Only a pending ReadIfReady() can be canceled. |
| 236 | DCHECK(!user_buffer_) << "Pending Read() cannot be canceled"; |
| 237 | read_callback_.Reset(); |
| 238 | return OK; |
| 239 | } |
| 240 | |
[email protected] | ca690b0 | 2013-04-17 10:38:43 | [diff] [blame] | 241 | size_t SpdyProxyClientSocket::PopulateUserReadBuffer(char* data, size_t len) { |
[email protected] | 09a8d917 | 2013-04-17 19:23:49 | [diff] [blame] | 242 | return read_buffer_queue_.Dequeue(data, len); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 243 | } |
| 244 | |
[email protected] | a2b2cfc | 2017-12-06 09:06:08 | [diff] [blame] | 245 | int SpdyProxyClientSocket::Write( |
| 246 | IOBuffer* buf, |
| 247 | int buf_len, |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 248 | CompletionOnceCallback callback, |
[email protected] | a2b2cfc | 2017-12-06 09:06:08 | [diff] [blame] | 249 | const NetworkTrafficAnnotationTag& traffic_annotation) { |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 250 | DCHECK(write_callback_.is_null()); |
[email protected] | 194c7a9 | 2011-12-03 04:54:18 | [diff] [blame] | 251 | if (next_state_ != STATE_OPEN) |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 252 | return ERR_SOCKET_NOT_CONNECTED; |
| 253 | |
[email protected] | 11fbca0b | 2013-06-02 23:37:21 | [diff] [blame] | 254 | DCHECK(spdy_stream_.get()); |
[email protected] | edbfa8c | 2013-05-29 00:22:33 | [diff] [blame] | 255 | spdy_stream_->SendData(buf, buf_len, MORE_DATA_TO_SEND); |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 256 | net_log_.AddByteTransferEvent(NetLogEventType::SOCKET_BYTES_SENT, buf_len, |
| 257 | buf->data()); |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 258 | write_callback_ = std::move(callback); |
[email protected] | aa19cfc | 2013-05-23 16:41:38 | [diff] [blame] | 259 | write_buffer_len_ = buf_len; |
| 260 | return ERR_IO_PENDING; |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 261 | } |
| 262 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 263 | int SpdyProxyClientSocket::SetReceiveBufferSize(int32_t size) { |
[email protected] | 3268023f | 2011-05-05 00:08:10 | [diff] [blame] | 264 | // Since this StreamSocket sits on top of a shared SpdySession, it |
[email protected] | 28b96d1c | 2014-04-09 12:21:15 | [diff] [blame] | 265 | // is not safe for callers to change this underlying socket. |
| 266 | return ERR_NOT_IMPLEMENTED; |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 267 | } |
| 268 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 269 | int SpdyProxyClientSocket::SetSendBufferSize(int32_t size) { |
[email protected] | 3268023f | 2011-05-05 00:08:10 | [diff] [blame] | 270 | // Since this StreamSocket sits on top of a shared SpdySession, it |
[email protected] | 28b96d1c | 2014-04-09 12:21:15 | [diff] [blame] | 271 | // is not safe for callers to change this underlying socket. |
| 272 | return ERR_NOT_IMPLEMENTED; |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 273 | } |
| 274 | |
[email protected] | a352869 | 2012-06-08 00:11:42 | [diff] [blame] | 275 | int SpdyProxyClientSocket::GetPeerAddress(IPEndPoint* address) const { |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 276 | if (!IsConnected()) |
[email protected] | 88e03fa | 2010-10-05 03:09:04 | [diff] [blame] | 277 | return ERR_SOCKET_NOT_CONNECTED; |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 278 | return spdy_stream_->GetPeerAddress(address); |
| 279 | } |
| 280 | |
[email protected] | e7f74da | 2011-04-19 23:49:35 | [diff] [blame] | 281 | int SpdyProxyClientSocket::GetLocalAddress(IPEndPoint* address) const { |
| 282 | if (!IsConnected()) |
| 283 | return ERR_SOCKET_NOT_CONNECTED; |
| 284 | return spdy_stream_->GetLocalAddress(address); |
| 285 | } |
| 286 | |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 287 | void SpdyProxyClientSocket::RunCallback(CompletionOnceCallback callback, |
[email protected] | 0a428c2 | 2014-06-14 02:26:37 | [diff] [blame] | 288 | int result) const { |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 289 | std::move(callback).Run(result); |
[email protected] | 0a428c2 | 2014-06-14 02:26:37 | [diff] [blame] | 290 | } |
| 291 | |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 292 | void SpdyProxyClientSocket::OnIOComplete(int result) { |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 293 | DCHECK_NE(STATE_DISCONNECTED, next_state_); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 294 | int rv = DoLoop(result); |
| 295 | if (rv != ERR_IO_PENDING) { |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 296 | std::move(read_callback_).Run(rv); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | |
| 300 | int SpdyProxyClientSocket::DoLoop(int last_io_result) { |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 301 | DCHECK_NE(next_state_, STATE_DISCONNECTED); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 302 | int rv = last_io_result; |
| 303 | do { |
| 304 | State state = next_state_; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 305 | next_state_ = STATE_DISCONNECTED; |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 306 | switch (state) { |
| 307 | case STATE_GENERATE_AUTH_TOKEN: |
| 308 | DCHECK_EQ(OK, rv); |
| 309 | rv = DoGenerateAuthToken(); |
| 310 | break; |
| 311 | case STATE_GENERATE_AUTH_TOKEN_COMPLETE: |
| 312 | rv = DoGenerateAuthTokenComplete(rv); |
| 313 | break; |
| 314 | case STATE_SEND_REQUEST: |
| 315 | DCHECK_EQ(OK, rv); |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 316 | net_log_.BeginEvent( |
| 317 | NetLogEventType::HTTP_TRANSACTION_TUNNEL_SEND_REQUEST); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 318 | rv = DoSendRequest(); |
| 319 | break; |
| 320 | case STATE_SEND_REQUEST_COMPLETE: |
[email protected] | d7fd178 | 2011-02-08 19:16:43 | [diff] [blame] | 321 | net_log_.EndEventWithNetErrorCode( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 322 | NetLogEventType::HTTP_TRANSACTION_TUNNEL_SEND_REQUEST, rv); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 323 | rv = DoSendRequestComplete(rv); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 324 | if (rv >= 0 || rv == ERR_IO_PENDING) { |
| 325 | // Emit extra event so can use the same events as |
| 326 | // HttpProxyClientSocket. |
| 327 | net_log_.BeginEvent( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 328 | NetLogEventType::HTTP_TRANSACTION_TUNNEL_READ_HEADERS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 329 | } |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 330 | break; |
| 331 | case STATE_READ_REPLY_COMPLETE: |
| 332 | rv = DoReadReplyComplete(rv); |
[email protected] | d7fd178 | 2011-02-08 19:16:43 | [diff] [blame] | 333 | net_log_.EndEventWithNetErrorCode( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 334 | NetLogEventType::HTTP_TRANSACTION_TUNNEL_READ_HEADERS, rv); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 335 | break; |
| 336 | default: |
| 337 | NOTREACHED() << "bad state"; |
| 338 | rv = ERR_UNEXPECTED; |
| 339 | break; |
| 340 | } |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 341 | } while (rv != ERR_IO_PENDING && next_state_ != STATE_DISCONNECTED && |
| 342 | next_state_ != STATE_OPEN); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 343 | return rv; |
| 344 | } |
| 345 | |
| 346 | int SpdyProxyClientSocket::DoGenerateAuthToken() { |
| 347 | next_state_ = STATE_GENERATE_AUTH_TOKEN_COMPLETE; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 348 | return auth_->MaybeGenerateAuthToken( |
| 349 | &request_, |
Yannic Bonenberger | 00e0984 | 2019-08-31 20:46:19 | [diff] [blame] | 350 | base::BindOnce(&SpdyProxyClientSocket::OnIOComplete, |
| 351 | weak_factory_.GetWeakPtr()), |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 352 | net_log_); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | int SpdyProxyClientSocket::DoGenerateAuthTokenComplete(int result) { |
| 356 | DCHECK_NE(ERR_IO_PENDING, result); |
| 357 | if (result == OK) |
| 358 | next_state_ = STATE_SEND_REQUEST; |
| 359 | return result; |
| 360 | } |
| 361 | |
| 362 | int SpdyProxyClientSocket::DoSendRequest() { |
| 363 | next_state_ = STATE_SEND_REQUEST_COMPLETE; |
| 364 | |
| 365 | // Add Proxy-Authentication header if necessary. |
| 366 | HttpRequestHeaders authorization_headers; |
| 367 | if (auth_->HaveAuth()) { |
| 368 | auth_->AddAuthorizationHeader(&authorization_headers); |
| 369 | } |
| 370 | |
Robert Ogden | 78d4f9eb | 2020-03-17 20:56:38 | [diff] [blame] | 371 | if (proxy_delegate_) { |
| 372 | HttpRequestHeaders proxy_delegate_headers; |
| 373 | proxy_delegate_->OnBeforeTunnelRequest(proxy_server_, |
| 374 | &proxy_delegate_headers); |
| 375 | request_.extra_headers.MergeFrom(proxy_delegate_headers); |
| 376 | } |
| 377 | |
Bence Béky | 4e83f49 | 2018-05-13 23:14:25 | [diff] [blame] | 378 | std::string request_line; |
rch | ecd3c55 | 2015-04-07 20:53:54 | [diff] [blame] | 379 | BuildTunnelRequest(endpoint_, authorization_headers, user_agent_, |
| 380 | &request_line, &request_.extra_headers); |
[email protected] | 3abacd6 | 2012-06-10 20:20:32 | [diff] [blame] | 381 | |
Eric Roman | 06bd974 | 2019-07-13 15:19:13 | [diff] [blame] | 382 | NetLogRequestHeaders(net_log_, |
| 383 | NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 384 | request_line, &request_.extra_headers); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 385 | |
Bence Béky | 4c325e5 | 2020-10-22 20:48:01 | [diff] [blame] | 386 | spdy::Http2HeaderBlock headers; |
Bence Béky | 1af94d6f | 2018-02-08 00:40:14 | [diff] [blame] | 387 | CreateSpdyHeadersFromHttpRequest(request_, request_.extra_headers, &headers); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 388 | |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 389 | return spdy_stream_->SendRequestHeaders(std::move(headers), |
| 390 | MORE_DATA_TO_SEND); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | int SpdyProxyClientSocket::DoSendRequestComplete(int result) { |
| 394 | if (result < 0) |
| 395 | return result; |
| 396 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 397 | // Wait for HEADERS frame from the server |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 398 | next_state_ = STATE_READ_REPLY_COMPLETE; |
| 399 | return ERR_IO_PENDING; |
| 400 | } |
| 401 | |
| 402 | int SpdyProxyClientSocket::DoReadReplyComplete(int result) { |
| 403 | // We enter this method directly from DoSendRequestComplete, since |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 404 | // we are notified by a callback when the HEADERS frame arrives. |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 405 | |
| 406 | if (result < 0) |
| 407 | return result; |
| 408 | |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 409 | // Require the "HTTP/1.x" status line for SSL CONNECT. |
bnc | be0f6af | 2015-10-15 17:49:56 | [diff] [blame] | 410 | if (response_.headers->GetHttpVersion() < HttpVersion(1, 0)) |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 411 | return ERR_TUNNEL_CONNECTION_FAILED; |
| 412 | |
Eric Roman | 06bd974 | 2019-07-13 15:19:13 | [diff] [blame] | 413 | NetLogResponseHeaders( |
| 414 | net_log_, NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 415 | response_.headers.get()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 416 | |
Robert Ogden | 78d4f9eb | 2020-03-17 20:56:38 | [diff] [blame] | 417 | if (proxy_delegate_) { |
| 418 | int rv = proxy_delegate_->OnTunnelHeadersReceived(proxy_server_, |
| 419 | *response_.headers); |
| 420 | if (rv != OK) { |
| 421 | DCHECK_NE(ERR_IO_PENDING, rv); |
| 422 | return rv; |
| 423 | } |
| 424 | } |
| 425 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 426 | switch (response_.headers->response_code()) { |
| 427 | case 200: // OK |
| 428 | next_state_ = STATE_OPEN; |
| 429 | return OK; |
| 430 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 431 | case 407: // Proxy Authentication Required |
| 432 | next_state_ = STATE_OPEN; |
Jeremy Roman | 4803d233 | 2021-04-26 22:37:22 | [diff] [blame^] | 433 | SanitizeProxyAuth(response_); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 434 | return HandleProxyAuthChallenge(auth_.get(), &response_, net_log_); |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 435 | |
| 436 | default: |
| 437 | // Ignore response to avoid letting the proxy impersonate the target |
| 438 | // server. (See http://crbug.com/137891.) |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 439 | return ERR_TUNNEL_CONNECTION_FAILED; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 440 | } |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | // SpdyStream::Delegate methods: |
| 444 | // Called when SYN frame has been sent. |
| 445 | // Returns true if no more data to be sent after SYN frame. |
bnc | 4c21431 | 2016-11-28 16:49:15 | [diff] [blame] | 446 | void SpdyProxyClientSocket::OnHeadersSent() { |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 447 | DCHECK_EQ(next_state_, STATE_SEND_REQUEST_COMPLETE); |
| 448 | |
[email protected] | d46715c | 2013-04-15 00:21:42 | [diff] [blame] | 449 | OnIOComplete(OK); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 450 | } |
| 451 | |
Kenichi Ishibashi | 7415553 | 2021-03-13 01:38:06 | [diff] [blame] | 452 | void SpdyProxyClientSocket::OnEarlyHintsReceived( |
| 453 | const spdy::Http2HeaderBlock& headers) {} |
| 454 | |
bnc | 4c21431 | 2016-11-28 16:49:15 | [diff] [blame] | 455 | void SpdyProxyClientSocket::OnHeadersReceived( |
Bence Béky | 4c325e5 | 2020-10-22 20:48:01 | [diff] [blame] | 456 | const spdy::Http2HeaderBlock& response_headers, |
| 457 | const spdy::Http2HeaderBlock* pushed_request_headers) { |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 458 | // If we've already received the reply, existing headers are too late. |
| 459 | // TODO(mbelshe): figure out a way to make HEADERS frames useful after the |
| 460 | // initial response. |
| 461 | if (next_state_ != STATE_READ_REPLY_COMPLETE) |
bnc | 4c21431 | 2016-11-28 16:49:15 | [diff] [blame] | 462 | return; |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 463 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 464 | // Save the response |
bnc | 4c21431 | 2016-11-28 16:49:15 | [diff] [blame] | 465 | const bool headers_valid = |
| 466 | SpdyHeadersToHttpResponse(response_headers, &response_); |
| 467 | DCHECK(headers_valid); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 468 | |
[email protected] | 6d116e1a | 2013-06-24 07:42:15 | [diff] [blame] | 469 | OnIOComplete(OK); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 470 | } |
| 471 | |
[email protected] | ca690b0 | 2013-04-17 10:38:43 | [diff] [blame] | 472 | // Called when data is received or on EOF (if |buffer| is NULL). |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 473 | void SpdyProxyClientSocket::OnDataReceived(std::unique_ptr<SpdyBuffer> buffer) { |
[email protected] | ca690b0 | 2013-04-17 10:38:43 | [diff] [blame] | 474 | if (buffer) { |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 475 | net_log_.AddByteTransferEvent(NetLogEventType::SOCKET_BYTES_RECEIVED, |
[email protected] | ca690b0 | 2013-04-17 10:38:43 | [diff] [blame] | 476 | buffer->GetRemainingSize(), |
| 477 | buffer->GetRemainingData()); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 478 | read_buffer_queue_.Enqueue(std::move(buffer)); |
[email protected] | ca690b0 | 2013-04-17 10:38:43 | [diff] [blame] | 479 | } else { |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 480 | net_log_.AddByteTransferEvent(NetLogEventType::SOCKET_BYTES_RECEIVED, 0, |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 481 | nullptr); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 482 | } |
| 483 | |
Helen Li | d714188 | 2018-08-22 21:41:17 | [diff] [blame] | 484 | if (read_callback_) { |
| 485 | if (user_buffer_) { |
| 486 | int rv = PopulateUserReadBuffer(user_buffer_->data(), user_buffer_len_); |
| 487 | user_buffer_ = nullptr; |
| 488 | user_buffer_len_ = 0; |
| 489 | std::move(read_callback_).Run(rv); |
| 490 | } else { |
| 491 | // If ReadIfReady() is used instead of Read(), tell the caller that data |
| 492 | // is available for reading. |
| 493 | std::move(read_callback_).Run(OK); |
| 494 | } |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | |
[email protected] | aa19cfc | 2013-05-23 16:41:38 | [diff] [blame] | 498 | void SpdyProxyClientSocket::OnDataSent() { |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 499 | DCHECK(!write_callback_.is_null()); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 500 | |
[email protected] | aa19cfc | 2013-05-23 16:41:38 | [diff] [blame] | 501 | int rv = write_buffer_len_; |
| 502 | write_buffer_len_ = 0; |
[email protected] | 89d4d79 | 2014-04-06 16:27:15 | [diff] [blame] | 503 | |
| 504 | // Proxy write callbacks result in deep callback chains. Post to allow the |
| 505 | // stream's write callback chain to unwind (see crbug.com/355511). |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 506 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 507 | FROM_HERE, base::BindOnce(&SpdyProxyClientSocket::RunCallback, |
| 508 | write_callback_weak_factory_.GetWeakPtr(), |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 509 | std::move(write_callback_), rv)); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 510 | } |
| 511 | |
Bence Béky | 4c325e5 | 2020-10-22 20:48:01 | [diff] [blame] | 512 | void SpdyProxyClientSocket::OnTrailers(const spdy::Http2HeaderBlock& trailers) { |
xunjieli | 294da72 | 2015-08-11 19:15:02 | [diff] [blame] | 513 | // |spdy_stream_| is of type SPDY_BIDIRECTIONAL_STREAM, so trailers are |
| 514 | // combined with response headers and this method will not be calld. |
| 515 | NOTREACHED(); |
| 516 | } |
| 517 | |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 518 | void SpdyProxyClientSocket::OnClose(int status) { |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 519 | was_ever_used_ = spdy_stream_->WasEverUsed(); |
[email protected] | d26ff35 | 2013-05-13 08:48:28 | [diff] [blame] | 520 | spdy_stream_.reset(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 521 | |
| 522 | bool connecting = next_state_ != STATE_DISCONNECTED && |
| 523 | next_state_ < STATE_OPEN; |
| 524 | if (next_state_ == STATE_OPEN) |
| 525 | next_state_ = STATE_CLOSED; |
| 526 | else |
| 527 | next_state_ = STATE_DISCONNECTED; |
| 528 | |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 529 | base::WeakPtr<SpdyProxyClientSocket> weak_ptr = weak_factory_.GetWeakPtr(); |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 530 | CompletionOnceCallback write_callback = std::move(write_callback_); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 531 | write_buffer_len_ = 0; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 532 | |
| 533 | // If we're in the middle of connecting, we need to make sure |
| 534 | // we invoke the connect callback. |
| 535 | if (connecting) { |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 536 | DCHECK(!read_callback_.is_null()); |
Brad Lassey | 3a81417 | 2018-04-26 03:30:21 | [diff] [blame] | 537 | std::move(read_callback_).Run(status); |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 538 | } else if (!read_callback_.is_null()) { |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 539 | // If we have a read_callback_, the we need to make sure we call it back. |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 540 | OnDataReceived(std::unique_ptr<SpdyBuffer>()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 541 | } |
[email protected] | 6af4e41 | 2011-11-29 23:39:18 | [diff] [blame] | 542 | // This may have been deleted by read_callback_, so check first. |
[email protected] | 11fbca0b | 2013-06-02 23:37:21 | [diff] [blame] | 543 | if (weak_ptr.get() && !write_callback.is_null()) |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 544 | std::move(write_callback).Run(ERR_CONNECTION_CLOSED); |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 545 | } |
| 546 | |
Bence Béky | 21755dd6 | 2019-11-19 13:47:35 | [diff] [blame] | 547 | bool SpdyProxyClientSocket::CanGreaseFrameType() const { |
| 548 | return false; |
| 549 | } |
| 550 | |
bnc | 3d95ca9 | 2017-03-29 13:20:34 | [diff] [blame] | 551 | NetLogSource SpdyProxyClientSocket::source_dependency() const { |
| 552 | return source_dependency_; |
| 553 | } |
| 554 | |
[email protected] | fe2f62a | 2010-10-01 03:34:07 | [diff] [blame] | 555 | } // namespace net |