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