[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
| 5 | #ifndef NET_HTTP_HTTP_NETWORK_TRANSACTION_H_ |
| 6 | #define NET_HTTP_HTTP_NETWORK_TRANSACTION_H_ |
| 7 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10 | #include <memory> |
[email protected] | 96d570e4 | 2008-08-05 22:43:04 | [diff] [blame] | 11 | #include <string> |
| 12 | |
[email protected] | 8822f38 | 2010-07-30 21:49:03 | [diff] [blame] | 13 | #include "base/gtest_prod_util.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 14 | #include "base/macros.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 15 | #include "base/memory/ref_counted.h" |
[email protected] | 66e96c4 | 2013-06-28 15:20:31 | [diff] [blame] | 16 | #include "base/time/time.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 17 | #include "build/buildflag.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 18 | #include "crypto/ec_private_key.h" |
Bence Béky | 046f8c8 | 2018-06-12 02:26:04 | [diff] [blame] | 19 | #include "net/base/completion_once_callback.h" |
Bence Béky | 61f756c | 2018-04-25 14:17:53 | [diff] [blame] | 20 | #include "net/base/completion_repeating_callback.h" |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 21 | #include "net/base/net_error_details.h" |
bnc | 81c46c1f | 2016-10-04 16:25:59 | [diff] [blame] | 22 | #include "net/base/net_export.h" |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 23 | #include "net/base/network_isolation_key.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 24 | #include "net/base/request_priority.h" |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 25 | #include "net/http/http_auth.h" |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 26 | #include "net/http/http_request_headers.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 27 | #include "net/http/http_response_info.h" |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 28 | #include "net/http/http_stream_factory.h" |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 29 | #include "net/http/http_stream_request.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 30 | #include "net/http/http_transaction.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 31 | #include "net/log/net_log_with_source.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 32 | #include "net/net_buildflags.h" |
Nicolas Arciniega | 8ec5bfa | 2020-03-20 05:07:26 | [diff] [blame] | 33 | #include "net/proxy_resolution/proxy_resolution_service.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 34 | #include "net/socket/connection_attempts.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 35 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 36 | #include "net/websockets/websocket_handshake_stream_base.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 37 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 38 | namespace net { |
| 39 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 40 | class BidirectionalStreamImpl; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 41 | class HttpAuthController; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 42 | class HttpNetworkSession; |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 43 | class HttpStream; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 44 | class IOBuffer; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 45 | class ProxyInfo; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 46 | class SSLPrivateKey; |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 47 | struct HttpRequestInfo; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 48 | |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 49 | class NET_EXPORT_PRIVATE HttpNetworkTransaction |
| 50 | : public HttpTransaction, |
Helen Li | b495c380 | 2018-03-30 13:46:09 | [diff] [blame] | 51 | public HttpStreamRequest::Delegate { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 52 | public: |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 53 | HttpNetworkTransaction(RequestPriority priority, |
| 54 | HttpNetworkSession* session); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 55 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 56 | ~HttpNetworkTransaction() override; |
[email protected] | af4876d | 2008-10-21 23:10:57 | [diff] [blame] | 57 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 58 | // HttpTransaction methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 59 | int Start(const HttpRequestInfo* request_info, |
Bence Béky | 046f8c8 | 2018-06-12 02:26:04 | [diff] [blame] | 60 | CompletionOnceCallback callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 61 | const NetLogWithSource& net_log) override; |
Bence Béky | 046f8c8 | 2018-06-12 02:26:04 | [diff] [blame] | 62 | int RestartIgnoringLastError(CompletionOnceCallback callback) override; |
mattm | 436ccfe | 2017-06-19 20:24:08 | [diff] [blame] | 63 | int RestartWithCertificate(scoped_refptr<X509Certificate> client_cert, |
| 64 | scoped_refptr<SSLPrivateKey> client_private_key, |
Bence Béky | 046f8c8 | 2018-06-12 02:26:04 | [diff] [blame] | 65 | CompletionOnceCallback callback) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 66 | int RestartWithAuth(const AuthCredentials& credentials, |
Bence Béky | 046f8c8 | 2018-06-12 02:26:04 | [diff] [blame] | 67 | CompletionOnceCallback callback) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 68 | bool IsReadyToRestartForAuth() override; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 69 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 70 | int Read(IOBuffer* buf, |
| 71 | int buf_len, |
Bence Béky | 046f8c8 | 2018-06-12 02:26:04 | [diff] [blame] | 72 | CompletionOnceCallback callback) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 73 | void StopCaching() override; |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 74 | int64_t GetTotalReceivedBytes() const override; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 75 | int64_t GetTotalSentBytes() const override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 76 | void DoneReading() override; |
| 77 | const HttpResponseInfo* GetResponseInfo() const override; |
| 78 | LoadState GetLoadState() const override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 79 | void SetQuicServerInfo(QuicServerInfo* quic_server_info) override; |
| 80 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 81 | bool GetRemoteEndpoint(IPEndPoint* endpoint) const override; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 82 | void PopulateNetErrorDetails(NetErrorDetails* details) const override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 83 | void SetPriority(RequestPriority priority) override; |
| 84 | void SetWebSocketHandshakeStreamCreateHelper( |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 85 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 86 | void SetBeforeNetworkStartCallback( |
Will Cassella | 61125f9 | 2020-07-25 09:11:37 | [diff] [blame] | 87 | BeforeNetworkStartCallback callback) override; |
Titouan Rigoudy | 78af7da | 2020-07-07 14:30:12 | [diff] [blame] | 88 | void SetConnectedCallback(const ConnectedCallback& callback) override; |
Andrey Kosyakov | 2e893e6 | 2017-08-31 17:00:52 | [diff] [blame] | 89 | void SetRequestHeadersCallback(RequestHeadersCallback callback) override; |
| 90 | void SetResponseHeadersCallback(ResponseHeadersCallback callback) override; |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 91 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 92 | int ResumeNetworkStart() override; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 93 | |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 94 | // HttpStreamRequest::Delegate methods: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 95 | void OnStreamReady(const SSLConfig& used_ssl_config, |
| 96 | const ProxyInfo& used_proxy_info, |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 97 | std::unique_ptr<HttpStream> stream) override; |
| 98 | void OnBidirectionalStreamImplReady( |
| 99 | const SSLConfig& used_ssl_config, |
| 100 | const ProxyInfo& used_proxy_info, |
| 101 | std::unique_ptr<BidirectionalStreamImpl> stream) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 102 | void OnWebSocketHandshakeStreamReady( |
[email protected] | 3732cea | 2013-06-21 06:50:50 | [diff] [blame] | 103 | const SSLConfig& used_ssl_config, |
| 104 | const ProxyInfo& used_proxy_info, |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 105 | std::unique_ptr<WebSocketHandshakeStreamBase> stream) override; |
Ryan Hamilton | 75f19726 | 2017-08-17 14:00:07 | [diff] [blame] | 106 | void OnStreamFailed(int status, |
| 107 | const NetErrorDetails& net_error_details, |
Wojciech Dzierżanowski | abdeeaf | 2019-04-01 20:16:22 | [diff] [blame] | 108 | const SSLConfig& used_ssl_config, |
dalyk | 6d7a8c5 | 2019-12-18 21:43:01 | [diff] [blame] | 109 | const ProxyInfo& used_proxy_info, |
| 110 | ResolveErrorInfo resolve_error_info) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 111 | void OnCertificateError(int status, |
| 112 | const SSLConfig& used_ssl_config, |
| 113 | const SSLInfo& ssl_info) override; |
| 114 | void OnNeedsProxyAuth(const HttpResponseInfo& response_info, |
| 115 | const SSLConfig& used_ssl_config, |
| 116 | const ProxyInfo& used_proxy_info, |
| 117 | HttpAuthController* auth_controller) override; |
| 118 | void OnNeedsClientAuth(const SSLConfig& used_ssl_config, |
| 119 | SSLCertRequestInfo* cert_info) override; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 120 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 121 | void OnQuicBroken() override; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 122 | void GetConnectionAttempts(ConnectionAttempts* out) const override; |
| 123 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 124 | private: |
bnc | 1f61cdf | 2016-11-28 18:03:45 | [diff] [blame] | 125 | FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionTest, ResetStateForRestart); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 126 | FRIEND_TEST_ALL_PREFIXES(HttpNetworkTransactionTest, |
| 127 | CreateWebSocketHandshakeStream); |
bnc | 1f61cdf | 2016-11-28 18:03:45 | [diff] [blame] | 128 | FRIEND_TEST_ALL_PREFIXES(SpdyNetworkTransactionTest, WindowUpdateReceived); |
| 129 | FRIEND_TEST_ALL_PREFIXES(SpdyNetworkTransactionTest, WindowUpdateSent); |
| 130 | FRIEND_TEST_ALL_PREFIXES(SpdyNetworkTransactionTest, WindowUpdateOverflow); |
| 131 | FRIEND_TEST_ALL_PREFIXES(SpdyNetworkTransactionTest, FlowControlStallResume); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 132 | FRIEND_TEST_ALL_PREFIXES(SpdyNetworkTransactionTest, |
[email protected] | ca6459f86 | 2012-04-11 19:43:20 | [diff] [blame] | 133 | FlowControlStallResumeAfterSettings); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 134 | FRIEND_TEST_ALL_PREFIXES(SpdyNetworkTransactionTest, |
[email protected] | ca6459f86 | 2012-04-11 19:43:20 | [diff] [blame] | 135 | FlowControlNegativeSendWindowSize); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 136 | |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 137 | enum State { |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 138 | STATE_NOTIFY_BEFORE_CREATE_STREAM, |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 139 | STATE_CREATE_STREAM, |
| 140 | STATE_CREATE_STREAM_COMPLETE, |
[email protected] | 351ab64 | 2010-08-05 16:55:31 | [diff] [blame] | 141 | STATE_INIT_STREAM, |
| 142 | STATE_INIT_STREAM_COMPLETE, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 143 | STATE_GENERATE_PROXY_AUTH_TOKEN, |
| 144 | STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE, |
| 145 | STATE_GENERATE_SERVER_AUTH_TOKEN, |
| 146 | STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE, |
[email protected] | daddea6 | 2012-09-19 05:51:13 | [diff] [blame] | 147 | STATE_INIT_REQUEST_BODY, |
| 148 | STATE_INIT_REQUEST_BODY_COMPLETE, |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 149 | STATE_BUILD_REQUEST, |
| 150 | STATE_BUILD_REQUEST_COMPLETE, |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 151 | STATE_SEND_REQUEST, |
| 152 | STATE_SEND_REQUEST_COMPLETE, |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 153 | STATE_READ_HEADERS, |
| 154 | STATE_READ_HEADERS_COMPLETE, |
| 155 | STATE_READ_BODY, |
| 156 | STATE_READ_BODY_COMPLETE, |
| 157 | STATE_DRAIN_BODY_FOR_AUTH_RESTART, |
| 158 | STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE, |
| 159 | STATE_NONE |
| 160 | }; |
| 161 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 162 | bool IsSecureRequest() const; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 163 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 164 | // Returns true if the request is using an HTTP(S) proxy without being |
| 165 | // tunneled via the CONNECT method. |
| 166 | bool UsingHttpProxyWithoutTunnel() const; |
| 167 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 168 | void DoCallback(int result); |
| 169 | void OnIOComplete(int result); |
| 170 | |
| 171 | // Runs the state transition loop. |
| 172 | int DoLoop(int result); |
| 173 | |
| 174 | // Each of these methods corresponds to a State value. Those with an input |
| 175 | // argument receive the result from the previous state. If a method returns |
| 176 | // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the |
| 177 | // next state method as the result arg. |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 178 | int DoNotifyBeforeCreateStream(); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 179 | int DoCreateStream(); |
| 180 | int DoCreateStreamComplete(int result); |
[email protected] | 351ab64 | 2010-08-05 16:55:31 | [diff] [blame] | 181 | int DoInitStream(); |
| 182 | int DoInitStreamComplete(int result); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 183 | int DoGenerateProxyAuthToken(); |
| 184 | int DoGenerateProxyAuthTokenComplete(int result); |
| 185 | int DoGenerateServerAuthToken(); |
| 186 | int DoGenerateServerAuthTokenComplete(int result); |
[email protected] | daddea6 | 2012-09-19 05:51:13 | [diff] [blame] | 187 | int DoInitRequestBody(); |
| 188 | int DoInitRequestBodyComplete(int result); |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 189 | int DoBuildRequest(); |
| 190 | int DoBuildRequestComplete(int result); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 191 | int DoSendRequest(); |
| 192 | int DoSendRequestComplete(int result); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 193 | int DoReadHeaders(); |
| 194 | int DoReadHeadersComplete(int result); |
| 195 | int DoReadBody(); |
| 196 | int DoReadBodyComplete(int result); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 197 | int DoDrainBodyForAuthRestart(); |
| 198 | int DoDrainBodyForAuthRestartComplete(int result); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 199 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 200 | int BuildRequestHeaders(bool using_http_proxy_without_tunnel); |
[email protected] | 2979a49 | 2011-04-06 00:29:14 | [diff] [blame] | 201 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 202 | #if BUILDFLAG(ENABLE_REPORTING) |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 203 | // Processes the Report-To header, if one exists. This header configures where |
| 204 | // the Reporting API (in //net/reporting) will send reports for the origin. |
| 205 | void ProcessReportToHeader(); |
| 206 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 207 | // Processes the NEL header, if one exists. This header configures whether |
| 208 | // network errors will be reported to a specified group of endpoints using the |
| 209 | // Reporting API. |
| 210 | void ProcessNetworkErrorLoggingHeader(); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 211 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 212 | // Calls GenerateNetworkErrorLoggingReport() if |rv| represents a NET_ERROR |
| 213 | // other than ERR_IO_PENDING. |
| 214 | void GenerateNetworkErrorLoggingReportIfError(int rv); |
| 215 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 216 | // Generates a NEL report about this request. The NetworkErrorLoggingService |
| 217 | // will discard the report if there is no NEL policy registered for this |
| 218 | // origin. |
| 219 | void GenerateNetworkErrorLoggingReport(int rv); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 220 | #endif |
| 221 | |
[email protected] | 9f9f86c | 2009-03-12 22:32:42 | [diff] [blame] | 222 | // Writes a log message to help debugging in the field when we block a proxy |
| 223 | // response to a CONNECT request. |
[email protected] | af89ba6 | 2009-03-16 20:26:38 | [diff] [blame] | 224 | void LogBlockedTunnelResponse(int response_code) const; |
[email protected] | 9f9f86c | 2009-03-12 22:32:42 | [diff] [blame] | 225 | |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 226 | // Called wherever ERR_HTTP_1_1_REQUIRED or |
| 227 | // ERR_PROXY_HTTP_1_1_REQUIRED has to be handled. |
| 228 | int HandleHttp11Required(int error); |
| 229 | |
David Benjamin | 76a40ad | 2018-02-24 22:22:08 | [diff] [blame] | 230 | // Called to possibly handle a client authentication error. Sets next_state_ |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 231 | // and returns OK if recovering from the error. Otherwise, the same error |
| 232 | // code is returned. |
David Benjamin | 76a40ad | 2018-02-24 22:22:08 | [diff] [blame] | 233 | int HandleSSLClientAuthError(int error); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 234 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 235 | // Called to possibly recover from the given error. Sets next_state_ and |
| 236 | // returns OK if recovering from the error. Otherwise, the same error code |
| 237 | // is returned. |
| 238 | int HandleIOError(int error); |
| 239 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 240 | // Gets the response headers from the HttpStream. |
| 241 | HttpResponseHeaders* GetResponseHeaders() const; |
| 242 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 243 | // Called when the socket is unexpectedly closed. Returns true if the request |
| 244 | // should be resent in case of a socket reuse/close race. |
| 245 | bool ShouldResendRequest() const; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 246 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 247 | // Returns true if there have already been |kMaxRetryAttempts| retries for |
| 248 | // HTTP2 or QUIC network errors, and no further retries should be attempted. |
| 249 | bool HasExceededMaxRetries() const; |
| 250 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 251 | // Increments the number of restarts and returns true if the restart may |
| 252 | // proceed. |
| 253 | bool CheckMaxRestarts(); |
| 254 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 255 | // Resets the connection and the request headers for resend. Called when |
| 256 | // ShouldResendRequest() is true. |
| 257 | void ResetConnectionAndRequestForResend(); |
[email protected] | 2a5c76b | 2008-09-25 22:15:16 | [diff] [blame] | 258 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 259 | // Sets up the state machine to restart the transaction with auth. |
| 260 | void PrepareForAuthRestart(HttpAuth::Target target); |
| 261 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 262 | // Called when we don't need to drain the response body or have drained it. |
| 263 | // Resets |connection_| unless |keep_alive| is true, then calls |
| 264 | // ResetStateForRestart. Sets |next_state_| appropriately. |
| 265 | void DidDrainBodyForAuthRestart(bool keep_alive); |
| 266 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 267 | // Resets the members of the transaction so it can be restarted. |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 268 | void ResetStateForRestart(); |
| 269 | |
[email protected] | 697ef4c | 2010-10-14 16:38:58 | [diff] [blame] | 270 | // Resets the members of the transaction, except |stream_|, which needs |
| 271 | // to be maintained for multi-round auth. |
| 272 | void ResetStateForAuthRestart(); |
| 273 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 274 | // Caches network error details from the stream if available |
| 275 | // and resets the stream. |
| 276 | void CacheNetErrorDetailsAndResetStream(); |
| 277 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 278 | // Returns true if we should try to add a Proxy-Authorization header |
| 279 | bool ShouldApplyProxyAuth() const; |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 280 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 281 | // Returns true if we should try to add an Authorization header. |
| 282 | bool ShouldApplyServerAuth() const; |
| 283 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 284 | // Handles HTTP status code 401 or 407. |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 285 | // HandleAuthChallenge() returns a network error code, or OK on success. |
| 286 | // May update |pending_auth_target_| or |response_.auth_challenge|. |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 287 | int HandleAuthChallenge(); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 288 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 289 | // Returns true if we have auth credentials for the given target. |
| 290 | bool HaveAuth(HttpAuth::Target target) const; |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 291 | |
[email protected] | 228404f | 2010-06-24 04:31:41 | [diff] [blame] | 292 | // Get the {scheme, host, path, port} for the authentication target |
| 293 | GURL AuthURL(HttpAuth::Target target) const; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 294 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 295 | // Returns true if this transaction is for a WebSocket handshake |
| 296 | bool ForWebSocketHandshake() const; |
| 297 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 298 | void CopyConnectionAttemptsFromStreamRequest(); |
| 299 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 300 | // Returns true if response "Content-Encoding" headers respect |
| 301 | // "Accept-Encoding". |
| 302 | bool ContentEncodingsValid() const; |
| 303 | |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 304 | scoped_refptr<HttpAuthController> |
| 305 | auth_controllers_[HttpAuth::AUTH_NUM_TARGETS]; |
[email protected] | c3b35c2 | 2008-09-27 03:19:42 | [diff] [blame] | 306 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 307 | // Whether this transaction is waiting for proxy auth, server auth, or is |
| 308 | // not waiting for any auth at all. |pending_auth_target_| is read and |
| 309 | // cleared by RestartWithAuth(). |
| 310 | HttpAuth::Target pending_auth_target_; |
| 311 | |
Bence Béky | 61f756c | 2018-04-25 14:17:53 | [diff] [blame] | 312 | CompletionRepeatingCallback io_callback_; |
Bence Béky | 046f8c8 | 2018-06-12 02:26:04 | [diff] [blame] | 313 | CompletionOnceCallback callback_; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 314 | |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 315 | HttpNetworkSession* session_; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 316 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 317 | NetLogWithSource net_log_; |
shivanisha | 0b44085 | 2016-10-18 15:48:15 | [diff] [blame] | 318 | |
| 319 | // Reset to null at the start of the Read state machine. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 320 | const HttpRequestInfo* request_; |
shivanisha | 0b44085 | 2016-10-18 15:48:15 | [diff] [blame] | 321 | |
| 322 | // The requested URL. |
| 323 | GURL url_; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 324 | RequestPriority priority_; |
[email protected] | a7e4131 | 2009-12-16 23:18:14 | [diff] [blame] | 325 | HttpResponseInfo response_; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 326 | |
Matt Menke | b32ba512 | 2019-09-10 19:17:05 | [diff] [blame] | 327 | // Copied from |request_|, as it's needed after the response body has been |
| 328 | // read. |
| 329 | NetworkIsolationKey network_isolation_key_; |
| 330 | |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 331 | // |proxy_info_| is the ProxyInfo used by the HttpStreamRequest. |
[email protected] | 928fb58 | 2008-08-11 15:40:23 | [diff] [blame] | 332 | ProxyInfo proxy_info_; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 333 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 334 | std::unique_ptr<HttpStreamRequest> stream_request_; |
| 335 | std::unique_ptr<HttpStream> stream_; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 336 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 337 | // True if we've validated the headers that the stream parser has returned. |
| 338 | bool headers_valid_; |
| 339 | |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 340 | // True if we can send the request over early data. |
| 341 | bool can_send_early_data_; |
| 342 | |
David Benjamin | bac8dff | 2019-08-07 01:30:41 | [diff] [blame] | 343 | // True if the client certificate for the server (rather than the proxy) was |
| 344 | // configured in this transaction. |
| 345 | bool configured_client_cert_for_server_; |
David Benjamin | 76a40ad | 2018-02-24 22:22:08 | [diff] [blame] | 346 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 347 | // SSL configuration used for the server and proxy, respectively. Note |
| 348 | // |server_ssl_config_| may be updated from the HttpStreamFactory, which will |
| 349 | // be applied on retry. |
| 350 | // |
| 351 | // TODO(davidben): Mutating it is weird and relies on HttpStreamFactory |
| 352 | // modifications being idempotent. Address this as part of other work to make |
| 353 | // sense of SSLConfig (related to https://crbug.com/488043). |
[email protected] | 102957f | 2011-09-02 17:10:14 | [diff] [blame] | 354 | SSLConfig server_ssl_config_; |
| 355 | SSLConfig proxy_ssl_config_; |
[email protected] | c5949a3 | 2008-10-08 17:28:23 | [diff] [blame] | 356 | |
[email protected] | b94f92d | 2010-10-27 16:45:20 | [diff] [blame] | 357 | HttpRequestHeaders request_headers_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 358 | #if BUILDFLAG(ENABLE_REPORTING) |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 359 | // Whether a NEL report has already been generated. Reset when restarting. |
| 360 | bool network_error_logging_report_generated_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 361 | // Cache some fields from |request_| that we'll need to construct a NEL |
| 362 | // report about the request. (NEL report construction happens after we've |
| 363 | // cleared the |request_| pointer.) |
| 364 | std::string request_method_; |
| 365 | std::string request_referrer_; |
| 366 | std::string request_user_agent_; |
| 367 | int request_reporting_upload_depth_; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 368 | base::TimeTicks start_timeticks_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 369 | #endif |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 370 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 371 | // The size in bytes of the buffer we use to drain the response body that |
| 372 | // we want to throw away. The response body is typically a small error |
| 373 | // page just a few hundred bytes long. |
[email protected] | 81854c4 | 2010-09-22 03:39:36 | [diff] [blame] | 374 | static const int kDrainBodyBufferSize = 1024; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 375 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 376 | // User buffer and length passed to the Read method. |
[email protected] | 9dea9e1f | 2009-01-29 00:30:47 | [diff] [blame] | 377 | scoped_refptr<IOBuffer> read_buf_; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 378 | int read_buf_len_; |
| 379 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 380 | // Total number of bytes received on all destroyed HttpStreams for this |
| 381 | // transaction. |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 382 | int64_t total_received_bytes_; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 383 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 384 | // Total number of bytes sent on all destroyed HttpStreams for this |
| 385 | // transaction. |
| 386 | int64_t total_sent_bytes_; |
| 387 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 388 | // When the transaction started / finished sending the request, including |
| 389 | // the body, if present. |
| 390 | base::TimeTicks send_start_time_; |
| 391 | base::TimeTicks send_end_time_; |
| 392 | |
[email protected] | d207a5f | 2009-06-04 05:28:40 | [diff] [blame] | 393 | // The next state in the state machine. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 394 | State next_state_; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 395 | |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 396 | // True when the tunnel is in the process of being established - we can't |
| 397 | // read from the socket until the tunnel is done. |
| 398 | bool establishing_tunnel_; |
| 399 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 400 | // Enable pooling to a SpdySession with matching IP and certificate |
| 401 | // even if the SpdySessionKey is different. |
| 402 | bool enable_ip_based_pooling_; |
| 403 | |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 404 | // Enable using alternative services for the request. |
| 405 | bool enable_alternative_services_; |
| 406 | |
rch | 2f2991c | 2017-04-13 19:28:17 | [diff] [blame] | 407 | // When a request is retried because of errors with the alternative service, |
| 408 | // this will store the alternative service used. |
| 409 | AlternativeService retried_alternative_service_; |
| 410 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 411 | // The helper object to use to create WebSocketHandshakeStreamBase |
| 412 | // objects. Only relevant when establishing a WebSocket connection. |
| 413 | WebSocketHandshakeStreamBase::CreateHelper* |
| 414 | websocket_handshake_stream_base_create_helper_; |
| 415 | |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 416 | BeforeNetworkStartCallback before_network_start_callback_; |
Titouan Rigoudy | 78af7da | 2020-07-07 14:30:12 | [diff] [blame] | 417 | ConnectedCallback connected_callback_; |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 418 | RequestHeadersCallback request_headers_callback_; |
Andrey Kosyakov | 2e893e6 | 2017-08-31 17:00:52 | [diff] [blame] | 419 | ResponseHeadersCallback response_headers_callback_; |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 420 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 421 | ConnectionAttempts connection_attempts_; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 422 | IPEndPoint remote_endpoint_; |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 423 | // Network error details for this transaction. |
| 424 | NetErrorDetails net_error_details_; |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 425 | |
Bence Béky | d0d6950 | 2019-06-25 19:47:18 | [diff] [blame] | 426 | // Number of retries made for network errors like ERR_HTTP2_PING_FAILED, |
| 427 | // ERR_HTTP2_SERVER_REFUSED_STREAM, ERR_QUIC_HANDSHAKE_FAILED and |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 428 | // ERR_QUIC_PROTOCOL_ERROR. Currently we stop after 3 tries |
| 429 | // (including the initial request) and fail the request. |
| 430 | // This count excludes retries on reused sockets since a well |
| 431 | // behaved server may time those out and thus the number |
| 432 | // of times we can retry a request on reused sockets is limited. |
| 433 | size_t retry_attempts_; |
| 434 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 435 | // Number of times the transaction was restarted via a RestartWith* call. |
| 436 | size_t num_restarts_; |
| 437 | |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 438 | DISALLOW_COPY_AND_ASSIGN(HttpNetworkTransaction); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 439 | }; |
| 440 | |
| 441 | } // namespace net |
| 442 | |
| 443 | #endif // NET_HTTP_HTTP_NETWORK_TRANSACTION_H_ |