xref: /aosp_15_r20/external/cronet/net/url_request/url_request.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_URL_REQUEST_URL_REQUEST_H_
6 #define NET_URL_REQUEST_URL_REQUEST_H_
7 
8 #include <stdint.h>
9 
10 #include <memory>
11 #include <optional>
12 #include <string>
13 #include <string_view>
14 #include <vector>
15 
16 #include "base/containers/flat_set.h"
17 #include "base/memory/raw_ptr.h"
18 #include "base/memory/weak_ptr.h"
19 #include "base/supports_user_data.h"
20 #include "base/threading/thread_checker.h"
21 #include "base/time/time.h"
22 #include "base/types/pass_key.h"
23 #include "base/values.h"
24 #include "net/base/auth.h"
25 #include "net/base/completion_repeating_callback.h"
26 #include "net/base/idempotency.h"
27 #include "net/base/ip_endpoint.h"
28 #include "net/base/isolation_info.h"
29 #include "net/base/load_flags.h"
30 #include "net/base/load_states.h"
31 #include "net/base/load_timing_info.h"
32 #include "net/base/net_error_details.h"
33 #include "net/base/net_errors.h"
34 #include "net/base/net_export.h"
35 #include "net/base/network_delegate.h"
36 #include "net/base/proxy_chain.h"
37 #include "net/base/request_priority.h"
38 #include "net/base/upload_progress.h"
39 #include "net/cookies/canonical_cookie.h"
40 #include "net/cookies/cookie_partition_key.h"
41 #include "net/cookies/cookie_setting_override.h"
42 #include "net/cookies/site_for_cookies.h"
43 #include "net/dns/public/secure_dns_policy.h"
44 #include "net/filter/source_stream.h"
45 #include "net/http/http_raw_request_headers.h"
46 #include "net/http/http_request_headers.h"
47 #include "net/http/http_response_headers.h"
48 #include "net/http/http_response_info.h"
49 #include "net/log/net_log_event_type.h"
50 #include "net/log/net_log_source.h"
51 #include "net/log/net_log_with_source.h"
52 #include "net/net_buildflags.h"
53 #include "net/socket/connection_attempts.h"
54 #include "net/socket/socket_tag.h"
55 #include "net/traffic_annotation/network_traffic_annotation.h"
56 #include "net/url_request/redirect_info.h"
57 #include "net/url_request/referrer_policy.h"
58 #include "url/gurl.h"
59 #include "url/origin.h"
60 
61 namespace net {
62 
63 class CookieOptions;
64 class CookieInclusionStatus;
65 class IOBuffer;
66 struct LoadTimingInfo;
67 struct RedirectInfo;
68 class SSLCertRequestInfo;
69 class SSLInfo;
70 class SSLPrivateKey;
71 struct TransportInfo;
72 class UploadDataStream;
73 class URLRequestContext;
74 class URLRequestJob;
75 class X509Certificate;
76 
77 //-----------------------------------------------------------------------------
78 // A class  representing the asynchronous load of a data stream from an URL.
79 //
80 // The lifetime of an instance of this class is completely controlled by the
81 // consumer, and the instance is not required to live on the heap or be
82 // allocated in any special way.  It is also valid to delete an URLRequest
83 // object during the handling of a callback to its delegate.  Of course, once
84 // the URLRequest is deleted, no further callbacks to its delegate will occur.
85 //
86 // NOTE: All usage of all instances of this class should be on the same thread.
87 //
88 class NET_EXPORT URLRequest : public base::SupportsUserData {
89  public:
90   // Max number of http redirects to follow. The Fetch spec says: "If
91   // request's redirect count is twenty, return a network error."
92   // https://fetch.spec.whatwg.org/#http-redirect-fetch
93   static constexpr int kMaxRedirects = 20;
94 
95   // The delegate's methods are called from the message loop of the thread
96   // on which the request's Start() method is called. See above for the
97   // ordering of callbacks.
98   //
99   // The callbacks will be called in the following order:
100   //   Start()
101   //    - OnConnected* (zero or more calls, see method comment)
102   //    - OnCertificateRequested* (zero or more calls, if the SSL server and/or
103   //      SSL proxy requests a client certificate for authentication)
104   //    - OnSSLCertificateError* (zero or one call, if the SSL server's
105   //      certificate has an error)
106   //    - OnReceivedRedirect* (zero or more calls, for the number of redirects)
107   //    - OnAuthRequired* (zero or more calls, for the number of
108   //      authentication failures)
109   //    - OnResponseStarted
110   //   Read() initiated by delegate
111   //    - OnReadCompleted* (zero or more calls until all data is read)
112   //
113   // Read() must be called at least once. Read() returns bytes read when it
114   // completes immediately, and a negative error value if an IO is pending or if
115   // there is an error.
116   class NET_EXPORT Delegate {
117    public:
118     Delegate() = default;
119 
120     // Forbid copy and assign to prevent slicing.
121     Delegate(const Delegate&) = delete;
122     Delegate& operator=(const Delegate&) = delete;
123 
124     // Called each time a connection is obtained, before any data is sent.
125     //
126     // |request| is never nullptr. Caller retains ownership.
127     //
128     // |info| describes the newly-obtained connection.
129     //
130     // This may be called several times if the request creates multiple HTTP
131     // transactions, e.g. if the request is redirected. It may also be called
132     // several times per transaction, e.g. if the connection is retried, after
133     // each HTTP auth challenge, or for split HTTP range requests.
134     //
135     // If this returns an error, the transaction will stop. The transaction
136     // will continue when the |callback| is run. If run with an error, the
137     // transaction will fail.
138     virtual int OnConnected(URLRequest* request,
139                             const TransportInfo& info,
140                             CompletionOnceCallback callback);
141 
142     // Called upon receiving a redirect.  The delegate may call the request's
143     // Cancel method to prevent the redirect from being followed.  Since there
144     // may be multiple chained redirects, there may also be more than one
145     // redirect call.
146     //
147     // When this function is called, the request will still contain the
148     // original URL, the destination of the redirect is provided in
149     // |redirect_info.new_url|.  If the delegate does not cancel the request
150     // and |*defer_redirect| is false, then the redirect will be followed, and
151     // the request's URL will be changed to the new URL.  Otherwise if the
152     // delegate does not cancel the request and |*defer_redirect| is true, then
153     // the redirect will be followed once FollowDeferredRedirect is called
154     // on the URLRequest.
155     //
156     // The caller must set |*defer_redirect| to false, so that delegates do not
157     // need to set it if they are happy with the default behavior of not
158     // deferring redirect.
159     virtual void OnReceivedRedirect(URLRequest* request,
160                                     const RedirectInfo& redirect_info,
161                                     bool* defer_redirect);
162 
163     // Called when we receive an authentication failure.  The delegate should
164     // call request->SetAuth() with the user's credentials once it obtains them,
165     // or request->CancelAuth() to cancel the login and display the error page.
166     // When it does so, the request will be reissued, restarting the sequence
167     // of On* callbacks.
168     //
169     // NOTE: If auth_info.scheme is AUTH_SCHEME_NEGOTIATE on ChromeOS, this
170     // method should not call SetAuth(). Instead, it should show ChromeOS
171     // specific UI and cancel the request. (See b/260522530).
172     virtual void OnAuthRequired(URLRequest* request,
173                                 const AuthChallengeInfo& auth_info);
174 
175     // Called when we receive an SSL CertificateRequest message for client
176     // authentication.  The delegate should call
177     // request->ContinueWithCertificate() with the client certificate the user
178     // selected and its private key, or request->ContinueWithCertificate(NULL,
179     // NULL)
180     // to continue the SSL handshake without a client certificate.
181     virtual void OnCertificateRequested(URLRequest* request,
182                                         SSLCertRequestInfo* cert_request_info);
183 
184     // Called when using SSL and the server responds with a certificate with
185     // an error, for example, whose common name does not match the common name
186     // we were expecting for that host.  The delegate should either do the
187     // safe thing and Cancel() the request or decide to proceed by calling
188     // ContinueDespiteLastError().  cert_error is a ERR_* error code
189     // indicating what's wrong with the certificate.
190     // If |fatal| is true then the host in question demands a higher level
191     // of security (due e.g. to HTTP Strict Transport Security, user
192     // preference, or built-in policy). In this case, errors must not be
193     // bypassable by the user.
194     virtual void OnSSLCertificateError(URLRequest* request,
195                                        int net_error,
196                                        const SSLInfo& ssl_info,
197                                        bool fatal);
198 
199     // After calling Start(), the delegate will receive an OnResponseStarted
200     // callback when the request has completed. |net_error| will be set to OK
201     // or an actual net error.  On success, all redirects have been
202     // followed and the final response is beginning to arrive.  At this point,
203     // meta data about the response is available, including for example HTTP
204     // response headers if this is a request for a HTTP resource.
205     virtual void OnResponseStarted(URLRequest* request, int net_error);
206 
207     // Called when the a Read of the response body is completed after an
208     // IO_PENDING status from a Read() call.
209     // The data read is filled into the buffer which the caller passed
210     // to Read() previously.
211     //
212     // If an error occurred, |bytes_read| will be set to the error.
213     virtual void OnReadCompleted(URLRequest* request, int bytes_read) = 0;
214 
215    protected:
216     virtual ~Delegate() = default;
217   };
218 
219   // URLRequests are always created by calling URLRequestContext::CreateRequest.
220   URLRequest(base::PassKey<URLRequestContext> pass_key,
221              const GURL& url,
222              RequestPriority priority,
223              Delegate* delegate,
224              const URLRequestContext* context,
225              NetworkTrafficAnnotationTag traffic_annotation,
226              bool is_for_websockets,
227              std::optional<net::NetLogSource> net_log_source);
228 
229   URLRequest(const URLRequest&) = delete;
230   URLRequest& operator=(const URLRequest&) = delete;
231 
232   // If destroyed after Start() has been called but while IO is pending,
233   // then the request will be effectively canceled and the delegate
234   // will not have any more of its methods called.
235   ~URLRequest() override;
236 
237   // Changes the default cookie policy from allowing all cookies to blocking all
238   // cookies. Embedders that want to implement a more flexible policy should
239   // change the default to blocking all cookies, and provide a NetworkDelegate
240   // with the URLRequestContext that maintains the CookieStore.
241   // The cookie policy default has to be set before the first URLRequest is
242   // started. Once it was set to block all cookies, it cannot be changed back.
243   static void SetDefaultCookiePolicyToBlock();
244 
245   // The original url is the url used to initialize the request, and it may
246   // differ from the url if the request was redirected.
original_url()247   const GURL& original_url() const { return url_chain_.front(); }
248   // The chain of urls traversed by this request.  If the request had no
249   // redirects, this vector will contain one element.
url_chain()250   const std::vector<GURL>& url_chain() const { return url_chain_; }
url()251   const GURL& url() const { return url_chain_.back(); }
252 
253   // Explicitly set the URL chain for this request.  This can be used to
254   // indicate a chain of redirects that happen at a layer above the network
255   // service; e.g. navigation redirects.
256   //
257   // Note, the last entry in the new `url_chain` will be ignored.  Instead
258   // the request will preserve its current URL.  This is done since the higher
259   // layer providing the explicit `url_chain` may not be aware of modifications
260   // to the request URL by throttles.
261   //
262   // This method should only be called on new requests that have a single
263   // entry in their existing `url_chain_`.
264   void SetURLChain(const std::vector<GURL>& url_chain);
265 
266   // The URL that should be consulted for the third-party cookie blocking
267   // policy, as defined in Section 2.1.1 and 2.1.2 of
268   // https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site.
269   //
270   // WARNING: This URL must only be used for the third-party cookie blocking
271   //          policy. It MUST NEVER be used for any kind of SECURITY check.
272   //
273   //          For example, if a top-level navigation is redirected, the
274   //          first-party for cookies will be the URL of the first URL in the
275   //          redirect chain throughout the whole redirect. If it was used for
276   //          a security check, an attacker might try to get around this check
277   //          by starting from some page that redirects to the
278   //          host-to-be-attacked.
279   //
site_for_cookies()280   const SiteForCookies& site_for_cookies() const { return site_for_cookies_; }
281   // This method may only be called before Start().
282   void set_site_for_cookies(const SiteForCookies& site_for_cookies);
283 
284   // Sets IsolationInfo for the request, which affects whether SameSite cookies
285   // are sent, what NetworkAnonymizationKey is used for cached resources, and
286   // how that behavior changes when following redirects. This may only be
287   // changed before Start() is called.
288   //
289   // TODO(https://crbug.com/1060631): This isn't actually used yet for SameSite
290   // cookies. Update consumers and fix that.
set_isolation_info(const IsolationInfo & isolation_info)291   void set_isolation_info(const IsolationInfo& isolation_info) {
292     isolation_info_ = isolation_info;
293     cookie_partition_key_ = CookiePartitionKey::FromNetworkIsolationKey(
294         isolation_info.network_isolation_key(),
295         isolation_info_.site_for_cookies(), net::SchemefulSite(original_url()));
296   }
297 
298   // This will convert the passed NetworkAnonymizationKey to an IsolationInfo.
299   // This IsolationInfo mmay be assigned an inaccurate frame origin because the
300   // NetworkAnonymizationKey might not contain all the information to populate
301   // it. Additionally the NetworkAnonymizationKey uses sites which will be
302   // converted to origins when set on the IsolationInfo. If using this method it
303   // is required to skip the cache and not use credentials. Before starting the
304   // request, it must have the LoadFlag LOAD_DISABLE_CACHE set, and must be set
305   // to not allow credentials, to ensure that the inaccurate frame origin has no
306   // impact. The request will DCHECK otherwise.
307   void set_isolation_info_from_network_anonymization_key(
308       const NetworkAnonymizationKey& network_anonymization_key);
309 
isolation_info()310   const IsolationInfo& isolation_info() const { return isolation_info_; }
311 
cookie_partition_key()312   const std::optional<CookiePartitionKey>& cookie_partition_key() const {
313     return cookie_partition_key_;
314   }
315 
316   // Indicate whether SameSite cookies should be attached even though the
317   // request is cross-site.
force_ignore_site_for_cookies()318   bool force_ignore_site_for_cookies() const {
319     return force_ignore_site_for_cookies_;
320   }
set_force_ignore_site_for_cookies(bool attach)321   void set_force_ignore_site_for_cookies(bool attach) {
322     force_ignore_site_for_cookies_ = attach;
323   }
324 
325   // Indicates if the request should be treated as a main frame navigation for
326   // SameSite cookie computations.  This flag overrides the IsolationInfo
327   // request type associated with fetches from a service worker context.
force_main_frame_for_same_site_cookies()328   bool force_main_frame_for_same_site_cookies() const {
329     return force_main_frame_for_same_site_cookies_;
330   }
set_force_main_frame_for_same_site_cookies(bool value)331   void set_force_main_frame_for_same_site_cookies(bool value) {
332     force_main_frame_for_same_site_cookies_ = value;
333   }
334 
335   // Overrides pertaining to cookie settings for this particular request.
cookie_setting_overrides()336   CookieSettingOverrides& cookie_setting_overrides() {
337     return cookie_setting_overrides_;
338   }
cookie_setting_overrides()339   const CookieSettingOverrides& cookie_setting_overrides() const {
340     return cookie_setting_overrides_;
341   }
342 
343   // The first-party URL policy to apply when updating the first party URL
344   // during redirects. The first-party URL policy may only be changed before
345   // Start() is called.
first_party_url_policy()346   RedirectInfo::FirstPartyURLPolicy first_party_url_policy() const {
347     return first_party_url_policy_;
348   }
349   void set_first_party_url_policy(
350       RedirectInfo::FirstPartyURLPolicy first_party_url_policy);
351 
352   // The origin of the context which initiated the request. This is distinct
353   // from the "first party for cookies" discussed above in a number of ways:
354   //
355   // 1. The request's initiator does not change during a redirect. If a form
356   //    submission from `https://example.com/` redirects through a number of
357   //    sites before landing on `https://not-example.com/`, the initiator for
358   //    each of those requests will be `https://example.com/`.
359   //
360   // 2. The request's initiator is the origin of the frame or worker which made
361   //    the request, even for top-level navigations. That is, if
362   //    `https://example.com/`'s form submission is made in the top-level frame,
363   //    the first party for cookies would be the target URL's origin. The
364   //    initiator remains `https://example.com/`.
365   //
366   // This value is used to perform the cross-origin check specified in Section
367   // 4.3 of https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site.
368   //
369   // Note: the initiator can be null for browser-initiated top level
370   // navigations. This is different from a unique Origin (e.g. in sandboxed
371   // iframes).
initiator()372   const std::optional<url::Origin>& initiator() const { return initiator_; }
373   // This method may only be called before Start().
374   void set_initiator(const std::optional<url::Origin>& initiator);
375 
376   // The request method.  "GET" is the default value. The request method may
377   // only be changed before Start() is called. Request methods are
378   // case-sensitive, so standard HTTP methods like GET or POST should be
379   // specified in uppercase.
method()380   const std::string& method() const { return method_; }
381   void set_method(std::string_view method);
382 
383 #if BUILDFLAG(ENABLE_REPORTING)
384   // Reporting upload nesting depth of this request.
385   //
386   // If the request is not a Reporting upload, the depth is 0.
387   //
388   // If the request is a Reporting upload, the depth is the max of the depth
389   // of the requests reported within it plus 1. (Non-NEL reports are
390   // considered to have depth 0.)
reporting_upload_depth()391   int reporting_upload_depth() const { return reporting_upload_depth_; }
392   void set_reporting_upload_depth(int reporting_upload_depth);
393 #endif
394 
395   // The referrer URL for the request
referrer()396   const std::string& referrer() const { return referrer_; }
397   // Sets the referrer URL for the request. Can only be changed before Start()
398   // is called. |referrer| is sanitized to remove URL fragment, user name and
399   // password. If a referrer policy is set via set_referrer_policy(), then
400   // |referrer| should obey the policy; if it doesn't, it will be cleared when
401   // the request is started. The referrer URL may be suppressed or changed
402   // during the course of the request, for example because of a referrer policy
403   // set with set_referrer_policy().
404   void SetReferrer(std::string_view referrer);
405 
406   // The referrer policy to apply when updating the referrer during redirects.
407   // The referrer policy may only be changed before Start() is called. Any
408   // referrer set via SetReferrer() is expected to obey the policy set via
409   // set_referrer_policy(); otherwise the referrer will be cleared when the
410   // request is started.
referrer_policy()411   ReferrerPolicy referrer_policy() const { return referrer_policy_; }
412   void set_referrer_policy(ReferrerPolicy referrer_policy);
413 
414   // Sets whether credentials are allowed.
415   // If credentials are allowed, the request will send and save HTTP
416   // cookies, as well as authentication to the origin server. If not,
417   // they will not be sent, however proxy-level authentication will
418   // still occur. Setting this will force the LOAD_DO_NOT_SAVE_COOKIES field to
419   // be set in |load_flags_|. See https://crbug.com/799935.
420   void set_allow_credentials(bool allow_credentials);
allow_credentials()421   bool allow_credentials() const { return allow_credentials_; }
422 
423   // Sets the upload data.
424   void set_upload(std::unique_ptr<UploadDataStream> upload);
425 
426   // Gets the upload data.
427   const UploadDataStream* get_upload_for_testing() const;
428 
429   // Returns true if the request has a non-empty message body to upload.
430   bool has_upload() const;
431 
432   // Set or remove a extra request header.  These methods may only be called
433   // before Start() is called, or between receiving a redirect and trying to
434   // follow it.
435   void SetExtraRequestHeaderByName(std::string_view name,
436                                    std::string_view value,
437                                    bool overwrite);
438   void RemoveRequestHeaderByName(std::string_view name);
439 
440   // Sets all extra request headers.  Any extra request headers set by other
441   // methods are overwritten by this method.  This method may only be called
442   // before Start() is called.  It is an error to call it later.
443   void SetExtraRequestHeaders(const HttpRequestHeaders& headers);
444 
extra_request_headers()445   const HttpRequestHeaders& extra_request_headers() const {
446     return extra_request_headers_;
447   }
448 
449   // Gets the total amount of data received from network after SSL decoding and
450   // proxy handling. Pertains only to the last URLRequestJob issued by this
451   // URLRequest, i.e. reset on redirects, but not reset when multiple roundtrips
452   // are used for range requests or auth.
453   int64_t GetTotalReceivedBytes() const;
454 
455   // Gets the total amount of data sent over the network before SSL encoding and
456   // proxy handling. Pertains only to the last URLRequestJob issued by this
457   // URLRequest, i.e. reset on redirects, but not reset when multiple roundtrips
458   // are used for range requests or auth.
459   int64_t GetTotalSentBytes() const;
460 
461   // The size of the response body before removing any content encodings.
462   // Does not include redirects or sub-requests issued at lower levels (range
463   // requests or auth). Only includes bytes which have been read so far,
464   // including bytes from the cache.
465   int64_t GetRawBodyBytes() const;
466 
467   // Returns the current load state for the request. The returned value's
468   // |param| field is an optional parameter describing details related to the
469   // load state. Not all load states have a parameter.
470   LoadStateWithParam GetLoadState() const;
471 
472   // Returns a partial representation of the request's state as a value, for
473   // debugging.
474   base::Value::Dict GetStateAsValue() const;
475 
476   // Logs information about the what external object currently blocking the
477   // request.  LogUnblocked must be called before resuming the request.  This
478   // can be called multiple times in a row either with or without calling
479   // LogUnblocked between calls.  |blocked_by| must not be empty.
480   void LogBlockedBy(std::string_view blocked_by);
481 
482   // Just like LogBlockedBy, but also makes GetLoadState return source as the
483   // |param| in the value returned by GetLoadState.  Calling LogUnblocked or
484   // LogBlockedBy will clear the load param.  |blocked_by| must not be empty.
485   void LogAndReportBlockedBy(std::string_view blocked_by);
486 
487   // Logs that the request is no longer blocked by the last caller to
488   // LogBlockedBy.
489   void LogUnblocked();
490 
491   // Returns the current upload progress in bytes. When the upload data is
492   // chunked, size is set to zero, but position will not be.
493   UploadProgress GetUploadProgress() const;
494 
495   // Get response header(s) by name.  This method may only be called
496   // once the delegate's OnResponseStarted method has been called.  Headers
497   // that appear more than once in the response are coalesced, with values
498   // separated by commas (per RFC 2616). This will not work with cookies since
499   // comma can be used in cookie values.
500   void GetResponseHeaderByName(std::string_view name, std::string* value) const;
501 
502   // The time when |this| was constructed.
creation_time()503   base::TimeTicks creation_time() const { return creation_time_; }
504 
505   // The time at which the returned response was requested.  For cached
506   // responses, this is the last time the cache entry was validated.
request_time()507   const base::Time& request_time() const { return response_info_.request_time; }
508 
509   // The time at which the returned response was generated.  For cached
510   // responses, this is the last time the cache entry was validated.
response_time()511   const base::Time& response_time() const {
512     return response_info_.response_time;
513   }
514 
515   // Indicate if this response was fetched from disk cache.
was_cached()516   bool was_cached() const { return response_info_.was_cached; }
517 
518   // Returns true if the URLRequest was delivered over SPDY.
was_fetched_via_spdy()519   bool was_fetched_via_spdy() const {
520     return response_info_.was_fetched_via_spdy;
521   }
522 
523   // Returns the host and port that the content was fetched from.  See
524   // http_response_info.h for caveats relating to cached content.
525   IPEndPoint GetResponseRemoteEndpoint() const;
526 
527   // Get all response headers, as a HttpResponseHeaders object.  See comments
528   // in HttpResponseHeaders class as to the format of the data.
529   HttpResponseHeaders* response_headers() const;
530 
531   // Get the SSL connection info.
ssl_info()532   const SSLInfo& ssl_info() const { return response_info_.ssl_info; }
533 
534   const std::optional<AuthChallengeInfo>& auth_challenge_info() const;
535 
536   // Gets timing information related to the request.  Events that have not yet
537   // occurred are left uninitialized.  After a second request starts, due to
538   // a redirect or authentication, values will be reset.
539   //
540   // LoadTimingInfo only contains ConnectTiming information and socket IDs for
541   // non-cached HTTP responses.
542   void GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const;
543 
544   // Gets the networkd error details of the most recent origin that the network
545   // stack makes the request to.
546   void PopulateNetErrorDetails(NetErrorDetails* details) const;
547 
548   // Gets the remote endpoint of the most recent socket that the network stack
549   // used to make this request.
550   //
551   // Note that GetResponseRemoteEndpoint returns the |socket_address| field from
552   // HttpResponseInfo, which is only populated once the response headers are
553   // received, and can return cached values for cache revalidation requests.
554   // GetTransactionRemoteEndpoint will only return addresses from the current
555   // request.
556   //
557   // Returns true and fills in |endpoint| if the endpoint is available; returns
558   // false and leaves |endpoint| unchanged if it is unavailable.
559   bool GetTransactionRemoteEndpoint(IPEndPoint* endpoint) const;
560 
561   // Get the mime type.  This method may only be called once the delegate's
562   // OnResponseStarted method has been called.
563   void GetMimeType(std::string* mime_type) const;
564 
565   // Get the charset (character encoding).  This method may only be called once
566   // the delegate's OnResponseStarted method has been called.
567   void GetCharset(std::string* charset) const;
568 
569   // Returns the HTTP response code (e.g., 200, 404, and so on).  This method
570   // may only be called once the delegate's OnResponseStarted method has been
571   // called.  For non-HTTP requests, this method returns -1.
572   int GetResponseCode() const;
573 
574   // Get the HTTP response info in its entirety.
response_info()575   const HttpResponseInfo& response_info() const { return response_info_; }
576 
577   // Access the LOAD_* flags modifying this request (see load_flags.h).
load_flags()578   int load_flags() const { return load_flags_; }
579 
is_created_from_network_anonymization_key()580   bool is_created_from_network_anonymization_key() const {
581     return is_created_from_network_anonymization_key_;
582   }
583 
584   // Returns the Secure DNS Policy for the request.
secure_dns_policy()585   SecureDnsPolicy secure_dns_policy() const { return secure_dns_policy_; }
586 
587   void set_maybe_sent_cookies(CookieAccessResultList cookies);
588   void set_maybe_stored_cookies(CookieAndLineAccessResultList cookies);
589 
590   // These lists contain a list of cookies that are associated with the given
591   // request, both those that were sent and accepted, and those that were
592   // removed or flagged from the request before use. The status indicates
593   // whether they were actually used (INCLUDE), or the reason they were removed
594   // or flagged. They are cleared on redirects and other request restarts that
595   // cause sent cookies to be recomputed / new cookies to potentially be
596   // received (such as calling SetAuth() to send HTTP auth credentials, but not
597   // calling ContinueWithCertification() to respond to client cert challenges),
598   // and only contain the cookies relevant to the most recent roundtrip.
599 
600   // Populated while the http request is being built.
maybe_sent_cookies()601   const CookieAccessResultList& maybe_sent_cookies() const {
602     return maybe_sent_cookies_;
603   }
604   // Populated after the response headers are received.
maybe_stored_cookies()605   const CookieAndLineAccessResultList& maybe_stored_cookies() const {
606     return maybe_stored_cookies_;
607   }
608 
609   // The new flags may change the IGNORE_LIMITS flag only when called
610   // before Start() is called, it must only set the flag, and if set,
611   // the priority of this request must already be MAXIMUM_PRIORITY.
612   void SetLoadFlags(int flags);
613 
614   // Controls the Secure DNS behavior to use when creating the socket for this
615   // request.
616   void SetSecureDnsPolicy(SecureDnsPolicy secure_dns_policy);
617 
618   // Returns true if the request is "pending" (i.e., if Start() has been called,
619   // and the response has not yet been called).
is_pending()620   bool is_pending() const { return is_pending_; }
621 
622   // Returns true if the request is in the process of redirecting to a new
623   // URL but has not yet initiated the new request.
is_redirecting()624   bool is_redirecting() const { return is_redirecting_; }
625 
626   // This method is called to start the request.  The delegate will receive
627   // a OnResponseStarted callback when the request is started.  The request
628   // must have a delegate set before this method is called.
629   void Start();
630 
631   // This method may be called at any time after Start() has been called to
632   // cancel the request.  This method may be called many times, and it has
633   // no effect once the response has completed.  It is guaranteed that no
634   // methods of the delegate will be called after the request has been
635   // cancelled, except that this may call the delegate's OnReadCompleted()
636   // during the call to Cancel itself. Returns |ERR_ABORTED| or other net error
637   // if there was one.
638   int Cancel();
639 
640   // Cancels the request and sets the error to |error|, unless the request
641   // already failed with another error code (see net_error_list.h). Returns
642   // final network error code.
643   int CancelWithError(int error);
644 
645   // Cancels the request and sets the error to |error| (see net_error_list.h
646   // for values) and attaches |ssl_info| as the SSLInfo for that request.  This
647   // is useful to attach a certificate and certificate error to a canceled
648   // request.
649   void CancelWithSSLError(int error, const SSLInfo& ssl_info);
650 
651   // Read initiates an asynchronous read from the response, and must only be
652   // called after the OnResponseStarted callback is received with a net::OK. If
653   // data is available, length and the data will be returned immediately. If the
654   // request has failed, an error code will be returned. If data is not yet
655   // available, Read returns net::ERR_IO_PENDING, and the Delegate's
656   // OnReadComplete method will be called asynchronously with the result of the
657   // read, unless the URLRequest is canceled.
658   //
659   // The |buf| parameter is a buffer to receive the data. If the operation
660   // completes asynchronously, the implementation will reference the buffer
661   // until OnReadComplete is called. The buffer must be at least |max_bytes| in
662   // length.
663   //
664   // The |max_bytes| parameter is the maximum number of bytes to read.
665   int Read(IOBuffer* buf, int max_bytes);
666 
667   // This method may be called to follow a redirect that was deferred in
668   // response to an OnReceivedRedirect call. If non-null,
669   // |modified_headers| are changes applied to the request headers after
670   // updating them for the redirect.
671   void FollowDeferredRedirect(
672       const std::optional<std::vector<std::string>>& removed_headers,
673       const std::optional<net::HttpRequestHeaders>& modified_headers);
674 
675   // One of the following two methods should be called in response to an
676   // OnAuthRequired() callback (and only then).
677   // SetAuth will reissue the request with the given credentials.
678   // CancelAuth will give up and display the error page.
679   void SetAuth(const AuthCredentials& credentials);
680   void CancelAuth();
681 
682   // This method can be called after the user selects a client certificate to
683   // instruct this URLRequest to continue with the request with the
684   // certificate.  Pass NULL if the user doesn't have a client certificate.
685   void ContinueWithCertificate(scoped_refptr<X509Certificate> client_cert,
686                                scoped_refptr<SSLPrivateKey> client_private_key);
687 
688   // This method can be called after some error notifications to instruct this
689   // URLRequest to ignore the current error and continue with the request.  To
690   // cancel the request instead, call Cancel().
691   void ContinueDespiteLastError();
692 
693   // Aborts the request (without invoking any completion callbacks) and closes
694   // the current connection, rather than returning it to the socket pool. Only
695   // affects HTTP/1.1 connections and tunnels.
696   //
697   // Intended to be used in cases where socket reuse can potentially leak data
698   // across sites.
699   //
700   // May only be called after Delegate::OnResponseStarted() has been invoked
701   // with net::OK, but before the body has been completely read. After the last
702   // body has been read, the socket may have already been handed off to another
703   // consumer.
704   //
705   // Due to transactions potentially being shared by multiple URLRequests in
706   // some cases, it is possible the socket may not be immediately closed, but
707   // will instead be closed when all URLRequests sharing the socket have been
708   // destroyed.
709   void AbortAndCloseConnection();
710 
711   // Used to specify the context (cookie store, cache) for this request.
712   const URLRequestContext* context() const;
713 
714   // Returns context()->network_delegate().
715   NetworkDelegate* network_delegate() const;
716 
net_log()717   const NetLogWithSource& net_log() const { return net_log_; }
718 
719   // Returns the expected content size if available
720   int64_t GetExpectedContentSize() const;
721 
722   // Returns the priority level for this request.
priority()723   RequestPriority priority() const { return priority_; }
724 
725   // Returns the incremental loading priority flag for this request.
priority_incremental()726   bool priority_incremental() const { return priority_incremental_; }
727 
728   // Sets the priority level for this request and any related
729   // jobs. Must not change the priority to anything other than
730   // MAXIMUM_PRIORITY if the IGNORE_LIMITS load flag is set.
731   void SetPriority(RequestPriority priority);
732 
733   // Sets the incremental priority flag for this request.
734   void SetPriorityIncremental(bool priority_incremental);
735 
set_received_response_content_length(int64_t received_content_length)736   void set_received_response_content_length(int64_t received_content_length) {
737     received_response_content_length_ = received_content_length;
738   }
739 
740   // The number of bytes in the raw response body (before any decompression,
741   // etc.). This is only available after the final Read completes.
received_response_content_length()742   int64_t received_response_content_length() const {
743     return received_response_content_length_;
744   }
745 
746   // Available when the request headers are sent, which is before the more
747   // general response_info() is available.
proxy_chain()748   const ProxyChain& proxy_chain() const { return proxy_chain_; }
749 
750   // Gets the connection attempts made in the process of servicing this
751   // URLRequest. Only guaranteed to be valid if called after the request fails
752   // or after the response headers are received.
753   ConnectionAttempts GetConnectionAttempts() const;
754 
traffic_annotation()755   const NetworkTrafficAnnotationTag& traffic_annotation() const {
756     return traffic_annotation_;
757   }
758 
759   const std::optional<base::flat_set<net::SourceStream::SourceType>>&
accepted_stream_types()760   accepted_stream_types() const {
761     return accepted_stream_types_;
762   }
763 
set_accepted_stream_types(const std::optional<base::flat_set<net::SourceStream::SourceType>> & types)764   void set_accepted_stream_types(
765       const std::optional<base::flat_set<net::SourceStream::SourceType>>&
766           types) {
767     if (types) {
768       DCHECK(!types->contains(net::SourceStream::SourceType::TYPE_NONE));
769       DCHECK(!types->contains(net::SourceStream::SourceType::TYPE_UNKNOWN));
770     }
771     accepted_stream_types_ = types;
772   }
773 
774   // Sets a callback that will be invoked each time the request is about to
775   // be actually sent and will receive actual request headers that are about
776   // to hit the wire, including SPDY/QUIC internal headers.
777   //
778   // Can only be set once before the request is started.
779   void SetRequestHeadersCallback(RequestHeadersCallback callback);
780 
781   // Sets a callback that will be invoked each time the response is received
782   // from the remote party with the actual response headers received. Note this
783   // is different from response_headers() getter in that in case of revalidation
784   // request, the latter will return cached headers, while the callback will be
785   // called with a response from the server.
786   void SetResponseHeadersCallback(ResponseHeadersCallback callback);
787 
788   // Sets a callback that will be invoked each time a 103 Early Hints response
789   // is received from the remote party.
790   void SetEarlyResponseHeadersCallback(ResponseHeadersCallback callback);
791 
792   // Set a callback that will be invoked when a matching shared dictionary is
793   // available to determine whether it is allowed to use the dictionary.
794   void SetIsSharedDictionaryReadAllowedCallback(
795       base::RepeatingCallback<bool()> callback);
796 
797   // Sets socket tag to be applied to all sockets used to execute this request.
798   // Must be set before Start() is called.  Only currently supported for HTTP
799   // and HTTPS requests on Android; UID tagging requires
800   // MODIFY_NETWORK_ACCOUNTING permission.
801   // NOTE(pauljensen): Setting a tag disallows sharing of sockets with requests
802   // with other tags, which may adversely effect performance by prohibiting
803   // connection sharing. In other words use of multiplexed sockets (e.g. HTTP/2
804   // and QUIC) will only be allowed if all requests have the same socket tag.
805   void set_socket_tag(const SocketTag& socket_tag);
socket_tag()806   const SocketTag& socket_tag() const { return socket_tag_; }
807 
808   // |upgrade_if_insecure| should be set to true if this request (including
809   // redirects) should be upgraded to HTTPS due to an Upgrade-Insecure-Requests
810   // requirement.
set_upgrade_if_insecure(bool upgrade_if_insecure)811   void set_upgrade_if_insecure(bool upgrade_if_insecure) {
812     upgrade_if_insecure_ = upgrade_if_insecure;
813   }
upgrade_if_insecure()814   bool upgrade_if_insecure() const { return upgrade_if_insecure_; }
815 
816   // `ad_tagged` should be set to true if the request is thought to be related
817   // to advertising.
set_ad_tagged(bool ad_tagged)818   void set_ad_tagged(bool ad_tagged) { ad_tagged_ = ad_tagged; }
ad_tagged()819   bool ad_tagged() const { return ad_tagged_; }
820 
821   // By default, client certs will be sent (provided via
822   // Delegate::OnCertificateRequested) when cookies are disabled
823   // (LOAD_DO_NOT_SEND_COOKIES / LOAD_DO_NOT_SAVE_COOKIES). As described at
824   // https://crbug.com/775438, this is not the desired behavior. When
825   // |send_client_certs| is set to false, this will suppress the
826   // Delegate::OnCertificateRequested callback when cookies/credentials are also
827   // suppressed. This method has no effect if credentials are enabled (cookies
828   // saved and sent).
829   // TODO(https://crbug.com/775438): Remove this when the underlying
830   // issue is fixed.
set_send_client_certs(bool send_client_certs)831   void set_send_client_certs(bool send_client_certs) {
832     send_client_certs_ = send_client_certs;
833   }
send_client_certs()834   bool send_client_certs() const { return send_client_certs_; }
835 
is_for_websockets()836   bool is_for_websockets() const { return is_for_websockets_; }
837 
SetIdempotency(Idempotency idempotency)838   void SetIdempotency(Idempotency idempotency) { idempotency_ = idempotency; }
GetIdempotency()839   Idempotency GetIdempotency() const { return idempotency_; }
840 
set_has_storage_access(bool has_storage_access)841   void set_has_storage_access(bool has_storage_access) {
842     DCHECK(!is_pending_);
843     DCHECK(!has_notified_completion_);
844     has_storage_access_ = has_storage_access;
845   }
has_storage_access()846   bool has_storage_access() const { return has_storage_access_; }
847 
848   static bool DefaultCanUseCookies();
849 
850   base::WeakPtr<URLRequest> GetWeakPtr();
851 
852  protected:
853   // Allow the URLRequestJob class to control the is_pending() flag.
set_is_pending(bool value)854   void set_is_pending(bool value) { is_pending_ = value; }
855 
856   // Setter / getter for the status of the request. Status is represented as a
857   // net::Error code. See |status_|.
status()858   int status() const { return status_; }
859   void set_status(int status);
860 
861   // Returns true if the request failed or was cancelled.
862   bool failed() const;
863 
864   // Returns the error status of the request.
865 
866   // Allow the URLRequestJob to redirect this request. If non-null,
867   // |removed_headers| and |modified_headers| are changes
868   // applied to the request headers after updating them for the redirect.
869   void Redirect(const RedirectInfo& redirect_info,
870                 const std::optional<std::vector<std::string>>& removed_headers,
871                 const std::optional<net::HttpRequestHeaders>& modified_headers);
872 
873   // Called by URLRequestJob to allow interception when a redirect occurs.
874   void NotifyReceivedRedirect(const RedirectInfo& redirect_info,
875                               bool* defer_redirect);
876 
877  private:
878   friend class URLRequestJob;
879 
880   // For testing purposes.
881   // TODO(maksims): Remove this.
882   friend class TestNetworkDelegate;
883 
884   // Resumes or blocks a request paused by the NetworkDelegate::OnBeforeRequest
885   // handler. If |blocked| is true, the request is blocked and an error page is
886   // returned indicating so. This should only be called after Start is called
887   // and OnBeforeRequest returns true (signalling that the request should be
888   // paused).
889   void BeforeRequestComplete(int error);
890 
891   void StartJob(std::unique_ptr<URLRequestJob> job);
892 
893   // Restarting involves replacing the current job with a new one such as what
894   // happens when following a HTTP redirect.
895   void RestartWithJob(std::unique_ptr<URLRequestJob> job);
896   void PrepareToRestart();
897 
898   // Cancels the request and set the error and ssl info for this request to the
899   // passed values. Returns the error that was set.
900   int DoCancel(int error, const SSLInfo& ssl_info);
901 
902   // Called by the URLRequestJob when the headers are received, before any other
903   // method, to allow caching of load timing information.
904   void OnHeadersComplete();
905 
906   // Notifies the network delegate that the request has been completed.
907   // This does not imply a successful completion. Also a canceled request is
908   // considered completed.
909   void NotifyRequestCompleted();
910 
911   // Called by URLRequestJob to allow interception when the final response
912   // occurs.
913   void NotifyResponseStarted(int net_error);
914 
915   // These functions delegate to |delegate_|.  See URLRequest::Delegate for the
916   // meaning of these functions.
917   int NotifyConnected(const TransportInfo& info,
918                       CompletionOnceCallback callback);
919   void NotifyAuthRequired(std::unique_ptr<AuthChallengeInfo> auth_info);
920   void NotifyCertificateRequested(SSLCertRequestInfo* cert_request_info);
921   void NotifySSLCertificateError(int net_error,
922                                  const SSLInfo& ssl_info,
923                                  bool fatal);
924   void NotifyReadCompleted(int bytes_read);
925 
926   // This function delegates to the NetworkDelegate if it is not nullptr.
927   // Otherwise, cookies can be used unless SetDefaultCookiePolicyToBlock() has
928   // been called.
929   bool CanSetCookie(const net::CanonicalCookie& cookie,
930                     CookieOptions* options,
931                     const net::FirstPartySetMetadata& first_party_set_metadata,
932                     CookieInclusionStatus* inclusion_status) const;
933 
934   // Called just before calling a delegate that may block a request. |type|
935   // should be the delegate's event type,
936   // e.g. NetLogEventType::NETWORK_DELEGATE_AUTH_REQUIRED.
937   void OnCallToDelegate(NetLogEventType type);
938   // Called when the delegate lets a request continue.  Also called on
939   // cancellation. `error` is an optional error code associated with
940   // completion. It's only for logging purposes, and will not directly cancel
941   // the request if it's a value other than OK.
942   void OnCallToDelegateComplete(int error = OK);
943 
944   // Records the referrer policy of the given request, bucketed by
945   // whether the request is same-origin or not. To save computation,
946   // takes this fact as a boolean parameter rather than dynamically
947   // checking.
948   void RecordReferrerGranularityMetrics(bool request_is_same_origin) const;
949 
950   // Creates a partial IsolationInfo with the information accessible from the
951   // NetworkAnonymiationKey.
952   net::IsolationInfo CreateIsolationInfoFromNetworkAnonymizationKey(
953       const NetworkAnonymizationKey& network_anonymization_key);
954 
955   // Contextual information used for this request. Cannot be NULL. This contains
956   // most of the dependencies which are shared between requests (disk cache,
957   // cookie store, socket pool, etc.)
958   raw_ptr<const URLRequestContext> context_;
959 
960   // Tracks the time spent in various load states throughout this request.
961   NetLogWithSource net_log_;
962 
963   std::unique_ptr<URLRequestJob> job_;
964   std::unique_ptr<UploadDataStream> upload_data_stream_;
965 
966   std::vector<GURL> url_chain_;
967   SiteForCookies site_for_cookies_;
968 
969   IsolationInfo isolation_info_;
970   // The cookie partition key for the request. Partitioned cookies should be set
971   // using this key and only partitioned cookies with this partition key should
972   // be sent. The cookie partition key is optional(nullopt) if cookie
973   // partitioning is not enabled, or if the NIK has no top-frame site.
974   //
975   // Unpartitioned cookies are unaffected by this field.
976   std::optional<CookiePartitionKey> cookie_partition_key_ = std::nullopt;
977 
978   bool force_ignore_site_for_cookies_ = false;
979   bool force_main_frame_for_same_site_cookies_ = false;
980   CookieSettingOverrides cookie_setting_overrides_;
981 
982   std::optional<url::Origin> initiator_;
983   GURL delegate_redirect_url_;
984   std::string method_;  // "GET", "POST", etc. Case-sensitive.
985   std::string referrer_;
986   ReferrerPolicy referrer_policy_ =
987       ReferrerPolicy::CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
988   RedirectInfo::FirstPartyURLPolicy first_party_url_policy_ =
989       RedirectInfo::FirstPartyURLPolicy::NEVER_CHANGE_URL;
990   HttpRequestHeaders extra_request_headers_;
991   // Flags indicating the request type for the load. Expected values are LOAD_*
992   // enums above.
993   int load_flags_ = LOAD_NORMAL;
994   // Whether the request is allowed to send credentials in general. Set by
995   // caller.
996   bool allow_credentials_ = true;
997   // Whether the request is eligible for using storage access permission grant
998   // if one exists. Only set by caller when constructed and will not change
999   // during redirects.
1000   bool has_storage_access_ = false;
1001   SecureDnsPolicy secure_dns_policy_ = SecureDnsPolicy::kAllow;
1002 
1003   CookieAccessResultList maybe_sent_cookies_;
1004   CookieAndLineAccessResultList maybe_stored_cookies_;
1005 
1006 #if BUILDFLAG(ENABLE_REPORTING)
1007   int reporting_upload_depth_ = 0;
1008 #endif
1009 
1010   // Never access methods of the |delegate_| directly. Always use the
1011   // Notify... methods for this.
1012   raw_ptr<Delegate> delegate_;
1013 
1014   const bool is_for_websockets_;
1015 
1016   // Current error status of the job, as a net::Error code. When the job is
1017   // busy, it is ERR_IO_PENDING. When the job is idle (either completed, or
1018   // awaiting a call from the URLRequestDelegate before continuing the request),
1019   // it is OK. If the request has been cancelled without a specific error, it is
1020   // ERR_ABORTED. And on failure, it's the corresponding error code for that
1021   // error.
1022   //
1023   // |status_| may bounce between ERR_IO_PENDING and OK as a request proceeds,
1024   // but once an error is encountered or the request is canceled, it will take
1025   // the appropriate error code and never change again. If multiple failures
1026   // have been encountered, this will be the first error encountered.
1027   int status_ = OK;
1028 
1029   bool is_created_from_network_anonymization_key_ = false;
1030 
1031   // The HTTP response info, lazily initialized.
1032   HttpResponseInfo response_info_;
1033 
1034   // Tells us whether the job is outstanding. This is true from the time
1035   // Start() is called to the time we dispatch RequestComplete and indicates
1036   // whether the job is active.
1037   bool is_pending_ = false;
1038 
1039   // Indicates if the request is in the process of redirecting to a new
1040   // location.  It is true from the time the headers complete until a
1041   // new request begins.
1042   bool is_redirecting_ = false;
1043 
1044   // Number of times we're willing to redirect.  Used to guard against
1045   // infinite redirects.
1046   int redirect_limit_;
1047 
1048   // Cached value for use after we've orphaned the job handling the
1049   // first transaction in a request involving redirects.
1050   UploadProgress final_upload_progress_;
1051 
1052   // The priority level for this request.  Objects like
1053   // ClientSocketPool use this to determine which URLRequest to
1054   // allocate sockets to first.
1055   RequestPriority priority_;
1056 
1057   // The incremental flag for this request that indicates if it should be
1058   // loaded concurrently with other resources of the same priority for
1059   // protocols that support HTTP extensible priorities (RFC 9218).
1060   // Currently only used in HTTP/3.
1061   bool priority_incremental_ = kDefaultPriorityIncremental;
1062 
1063   // If |calling_delegate_| is true, the event type of the delegate being
1064   // called.
1065   NetLogEventType delegate_event_type_ = NetLogEventType::FAILED;
1066 
1067   // True if this request is currently calling a delegate, or is blocked waiting
1068   // for the URL request or network delegate to resume it.
1069   bool calling_delegate_ = false;
1070 
1071   // An optional parameter that provides additional information about what
1072   // |this| is currently being blocked by.
1073   std::string blocked_by_;
1074   bool use_blocked_by_as_load_param_ = false;
1075 
1076   // Safe-guard to ensure that we do not send multiple "I am completed"
1077   // messages to network delegate.
1078   // TODO(battre): Remove this. http://crbug.com/89049
1079   bool has_notified_completion_ = false;
1080 
1081   int64_t received_response_content_length_ = 0;
1082 
1083   base::TimeTicks creation_time_;
1084 
1085   // Timing information for the most recent request.  Its start times are
1086   // populated during Start(), and the rest are populated in OnResponseReceived.
1087   LoadTimingInfo load_timing_info_;
1088 
1089   // The proxy chain used for this request, if any.
1090   ProxyChain proxy_chain_;
1091 
1092   // If not null, the network service will not advertise any stream types
1093   // (via Accept-Encoding) that are not listed. Also, it will not attempt
1094   // decoding any non-listed stream types.
1095   std::optional<base::flat_set<net::SourceStream::SourceType>>
1096       accepted_stream_types_;
1097 
1098   const NetworkTrafficAnnotationTag traffic_annotation_;
1099 
1100   SocketTag socket_tag_;
1101 
1102   // See Set{Request|Response,EarlyResponse}HeadersCallback() above for details.
1103   RequestHeadersCallback request_headers_callback_;
1104   ResponseHeadersCallback early_response_headers_callback_;
1105   ResponseHeadersCallback response_headers_callback_;
1106 
1107   // See SetIsSharedDictionaryReadAllowedCallback() above for details.
1108   base::RepeatingCallback<bool()> is_shared_dictionary_read_allowed_callback_;
1109 
1110   bool upgrade_if_insecure_ = false;
1111 
1112   bool ad_tagged_ = false;
1113 
1114   bool send_client_certs_ = true;
1115 
1116   // Idempotency of the request.
1117   Idempotency idempotency_ = DEFAULT_IDEMPOTENCY;
1118 
1119   THREAD_CHECKER(thread_checker_);
1120 
1121   base::WeakPtrFactory<URLRequest> weak_factory_{this};
1122 };
1123 
1124 }  // namespace net
1125 
1126 #endif  // NET_URL_REQUEST_URL_REQUEST_H_
1127