chromium/net/url_request/url_request.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/url_request/url_request.h"

#include <utility>

#include "base/compiler_specific.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/rand_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/lock.h"
#include "base/task/single_thread_task_runner.h"
#include "base/types/pass_key.h"
#include "base/values.h"
#include "net/base/auth.h"
#include "net/base/features.h"
#include "net/base/io_buffer.h"
#include "net/base/load_flags.h"
#include "net/base/load_timing_info.h"
#include "net/base/net_errors.h"
#include "net/base/network_change_notifier.h"
#include "net/base/network_delegate.h"
#include "net/base/upload_data_stream.h"
#include "net/cert/x509_certificate.h"
#include "net/cookies/cookie_setting_override.h"
#include "net/cookies/cookie_store.h"
#include "net/cookies/cookie_util.h"
#include "net/dns/public/secure_dns_policy.h"
#include "net/http/http_log_util.h"
#include "net/http/http_util.h"
#include "net/log/net_log.h"
#include "net/log/net_log_event_type.h"
#include "net/log/net_log_source_type.h"
#include "net/socket/next_proto.h"
#include "net/ssl/ssl_cert_request_info.h"
#include "net/ssl/ssl_private_key.h"
#include "net/storage_access_api/status.h"
#include "net/url_request/redirect_info.h"
#include "net/url_request/redirect_util.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_error_job.h"
#include "net/url_request/url_request_job.h"
#include "net/url_request/url_request_job_factory.h"
#include "net/url_request/url_request_netlog_params.h"
#include "net/url_request/url_request_redirect_job.h"
#include "url/gurl.h"
#include "url/origin.h"

namespace net {

namespace {

// True once the first URLRequest was started.
bool g_url_requests_started =;

// True if cookies are accepted by default.
bool g_default_can_use_cookies =;

// When the URLRequest first assempts load timing information, it has the times
// at which each event occurred.  The API requires the time which the request
// was blocked on each phase.  This function handles the conversion.
//
// In the case of reusing a SPDY session, old proxy results may have been
// reused, so proxy resolution times may be before the request was started.
//
// Due to preconnect and late binding, it is also possible for the connection
// attempt to start before a request has been started, or proxy resolution
// completed.
//
// This functions fixes both those cases.
void ConvertRealLoadTimesToBlockingTimes(LoadTimingInfo* load_timing_info) {}

NetLogWithSource CreateNetLogWithSource(
    NetLog* net_log,
    std::optional<net::NetLogSource> net_log_source) {}

}  // namespace

///////////////////////////////////////////////////////////////////////////////
// URLRequest::Delegate

int URLRequest::Delegate::OnConnected(URLRequest* request,
                                      const TransportInfo& info,
                                      CompletionOnceCallback callback) {}

void URLRequest::Delegate::OnReceivedRedirect(URLRequest* request,
                                              const RedirectInfo& redirect_info,
                                              bool* defer_redirect) {}

void URLRequest::Delegate::OnAuthRequired(URLRequest* request,
                                          const AuthChallengeInfo& auth_info) {}

void URLRequest::Delegate::OnCertificateRequested(
    URLRequest* request,
    SSLCertRequestInfo* cert_request_info) {}

void URLRequest::Delegate::OnSSLCertificateError(URLRequest* request,
                                                 int net_error,
                                                 const SSLInfo& ssl_info,
                                                 bool is_hsts_ok) {}

void URLRequest::Delegate::OnResponseStarted(URLRequest* request,
                                             int net_error) {}

///////////////////////////////////////////////////////////////////////////////
// URLRequest

URLRequest::~URLRequest() {}

void URLRequest::set_upload(std::unique_ptr<UploadDataStream> upload) {}

const UploadDataStream* URLRequest::get_upload_for_testing() const {}

bool URLRequest::has_upload() const {}

void URLRequest::SetExtraRequestHeaderByName(std::string_view name,
                                             std::string_view value,
                                             bool overwrite) {}

void URLRequest::RemoveRequestHeaderByName(std::string_view name) {}

void URLRequest::SetExtraRequestHeaders(const HttpRequestHeaders& headers) {}

int64_t URLRequest::GetTotalReceivedBytes() const {}

int64_t URLRequest::GetTotalSentBytes() const {}

int64_t URLRequest::GetRawBodyBytes() const {}

LoadStateWithParam URLRequest::GetLoadState() const {}

base::Value::Dict URLRequest::GetStateAsValue() const {}

void URLRequest::LogBlockedBy(std::string_view blocked_by) {}

void URLRequest::LogAndReportBlockedBy(std::string_view source) {}

void URLRequest::LogUnblocked() {}

UploadProgress URLRequest::GetUploadProgress() const {}

void URLRequest::GetResponseHeaderByName(std::string_view name,
                                         std::string* value) const {}

IPEndPoint URLRequest::GetResponseRemoteEndpoint() const {}

HttpResponseHeaders* URLRequest::response_headers() const {}

const std::optional<AuthChallengeInfo>& URLRequest::auth_challenge_info()
    const {}

void URLRequest::GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const {}

void URLRequest::PopulateNetErrorDetails(NetErrorDetails* details) const {}

bool URLRequest::GetTransactionRemoteEndpoint(IPEndPoint* endpoint) const {}

void URLRequest::GetMimeType(std::string* mime_type) const {}

void URLRequest::GetCharset(std::string* charset) const {}

int URLRequest::GetResponseCode() const {}

void URLRequest::set_maybe_sent_cookies(CookieAccessResultList cookies) {}

void URLRequest::set_maybe_stored_cookies(
    CookieAndLineAccessResultList cookies) {}

void URLRequest::SetLoadFlags(int flags) {}

void URLRequest::SetSecureDnsPolicy(SecureDnsPolicy secure_dns_policy) {}

// static
void URLRequest::SetDefaultCookiePolicyToBlock() {}

void URLRequest::SetURLChain(const std::vector<GURL>& url_chain) {}

void URLRequest::set_site_for_cookies(const SiteForCookies& site_for_cookies) {}

void URLRequest::set_isolation_info(const IsolationInfo& isolation_info,
                                    std::optional<GURL> redirect_info_new_url) {}

void URLRequest::set_isolation_info_from_network_anonymization_key(
    const NetworkAnonymizationKey& network_anonymization_key) {}

void URLRequest::set_first_party_url_policy(
    RedirectInfo::FirstPartyURLPolicy first_party_url_policy) {}

void URLRequest::set_initiator(const std::optional<url::Origin>& initiator) {}

void URLRequest::set_method(std::string_view method) {}

#if BUILDFLAG(ENABLE_REPORTING)
void URLRequest::set_reporting_upload_depth(int reporting_upload_depth) {}
#endif

void URLRequest::SetReferrer(std::string_view referrer) {}

void URLRequest::set_referrer_policy(ReferrerPolicy referrer_policy) {}

void URLRequest::set_allow_credentials(bool allow_credentials) {}

void URLRequest::Start() {}

///////////////////////////////////////////////////////////////////////////////

URLRequest::URLRequest(base::PassKey<URLRequestContext> pass_key,
                       const GURL& url,
                       RequestPriority priority,
                       Delegate* delegate,
                       const URLRequestContext* context,
                       NetworkTrafficAnnotationTag traffic_annotation,
                       bool is_for_websockets,
                       std::optional<net::NetLogSource> net_log_source)
    :{}

void URLRequest::BeforeRequestComplete(int error) {}

void URLRequest::StartJob(std::unique_ptr<URLRequestJob> job) {}

void URLRequest::RestartWithJob(std::unique_ptr<URLRequestJob> job) {}

int URLRequest::Cancel() {}

int URLRequest::CancelWithError(int error) {}

void URLRequest::CancelWithSSLError(int error, const SSLInfo& ssl_info) {}

int URLRequest::DoCancel(int error, const SSLInfo& ssl_info) {}

int URLRequest::Read(IOBuffer* dest, int dest_size) {}

void URLRequest::set_status(int status) {}

bool URLRequest::failed() const {}

int URLRequest::NotifyConnected(const TransportInfo& info,
                                CompletionOnceCallback callback) {}

void URLRequest::NotifyReceivedRedirect(const RedirectInfo& redirect_info,
                                        bool* defer_redirect) {}

void URLRequest::NotifyResponseStarted(int net_error) {}

void URLRequest::FollowDeferredRedirect(
    const std::optional<std::vector<std::string>>& removed_headers,
    const std::optional<net::HttpRequestHeaders>& modified_headers) {}

void URLRequest::SetAuth(const AuthCredentials& credentials) {}

void URLRequest::CancelAuth() {}

void URLRequest::ContinueWithCertificate(
    scoped_refptr<X509Certificate> client_cert,
    scoped_refptr<SSLPrivateKey> client_private_key) {}

void URLRequest::ContinueDespiteLastError() {}

void URLRequest::AbortAndCloseConnection() {}

void URLRequest::PrepareToRestart() {}

void URLRequest::Redirect(
    const RedirectInfo& redirect_info,
    const std::optional<std::vector<std::string>>& removed_headers,
    const std::optional<net::HttpRequestHeaders>& modified_headers) {}

void URLRequest::RetryWithStorageAccess() {}

// static
bool URLRequest::DefaultCanUseCookies() {}

const URLRequestContext* URLRequest::context() const {}

NetworkDelegate* URLRequest::network_delegate() const {}

int64_t URLRequest::GetExpectedContentSize() const {}

void URLRequest::SetPriority(RequestPriority priority) {}

void URLRequest::SetPriorityIncremental(bool priority_incremental) {}

void URLRequest::NotifyAuthRequired(
    std::unique_ptr<AuthChallengeInfo> auth_info) {}

void URLRequest::NotifyCertificateRequested(
    SSLCertRequestInfo* cert_request_info) {}

void URLRequest::NotifySSLCertificateError(int net_error,
                                           const SSLInfo& ssl_info,
                                           bool fatal) {}

bool URLRequest::CanSetCookie(
    const net::CanonicalCookie& cookie,
    CookieOptions* options,
    const net::FirstPartySetMetadata& first_party_set_metadata,
    CookieInclusionStatus* inclusion_status) const {}

void URLRequest::NotifyReadCompleted(int bytes_read) {}

void URLRequest::OnHeadersComplete() {}

void URLRequest::NotifyRequestCompleted() {}

void URLRequest::OnCallToDelegate(NetLogEventType type) {}

void URLRequest::OnCallToDelegateComplete(int error) {}

void URLRequest::RecordReferrerGranularityMetrics(
    bool request_is_same_origin) const {}

IsolationInfo URLRequest::CreateIsolationInfoFromNetworkAnonymizationKey(
    const NetworkAnonymizationKey& network_anonymization_key) {}

ConnectionAttempts URLRequest::GetConnectionAttempts() const {}

void URLRequest::SetRequestHeadersCallback(RequestHeadersCallback callback) {}

void URLRequest::SetResponseHeadersCallback(ResponseHeadersCallback callback) {}

void URLRequest::SetEarlyResponseHeadersCallback(
    ResponseHeadersCallback callback) {}

void URLRequest::SetIsSharedDictionaryReadAllowedCallback(
    base::RepeatingCallback<bool()> callback) {}

void URLRequest::set_socket_tag(const SocketTag& socket_tag) {}

bool URLRequest::ShouldSetLoadWithStorageAccess() const {}

void URLRequest::SetSharedDictionaryGetter(
    SharedDictionaryGetter shared_dictionary_getter) {}

base::WeakPtr<URLRequest> URLRequest::GetWeakPtr() {}

}  // namespace net