#include "net/url_request/url_request_http_job.h"
#include <algorithm>
#include <iterator>
#include <memory>
#include <optional>
#include <string_view>
#include <utility>
#include <vector>
#include "base/base_switches.h"
#include "base/check_op.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/containers/adapters.h"
#include "base/feature_list.h"
#include "base/file_version_info.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/numerics/safe_conversions.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/types/optional_util.h"
#include "base/values.h"
#include "build/build_config.h"
#include "net/base/features.h"
#include "net/base/host_port_pair.h"
#include "net/base/http_user_agent_settings.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "net/base/network_anonymization_key.h"
#include "net/base/network_delegate.h"
#include "net/base/network_isolation_key.h"
#include "net/base/privacy_mode.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/base/schemeful_site.h"
#include "net/base/trace_constants.h"
#include "net/base/tracing.h"
#include "net/base/url_util.h"
#include "net/cert/cert_status_flags.h"
#include "net/cert/ct_policy_status.h"
#include "net/cert/known_roots.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_access_delegate.h"
#include "net/cookies/cookie_constants.h"
#include "net/cookies/cookie_partition_key.h"
#include "net/cookies/cookie_setting_override.h"
#include "net/cookies/cookie_store.h"
#include "net/cookies/cookie_util.h"
#include "net/cookies/parsed_cookie.h"
#include "net/filter/brotli_source_stream.h"
#include "net/filter/filter_source_stream.h"
#include "net/filter/gzip_source_stream.h"
#include "net/filter/source_stream.h"
#include "net/filter/zstd_source_stream.h"
#include "net/first_party_sets/first_party_set_entry.h"
#include "net/first_party_sets/first_party_set_metadata.h"
#include "net/first_party_sets/first_party_sets_cache_filter.h"
#include "net/http/http_content_disposition.h"
#include "net/http/http_log_util.h"
#include "net/http/http_network_session.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_response_info.h"
#include "net/http/http_status_code.h"
#include "net/http/http_transaction.h"
#include "net/http/http_transaction_factory.h"
#include "net/http/http_util.h"
#include "net/http/transport_security_state.h"
#include "net/log/net_log.h"
#include "net/log/net_log_event_type.h"
#include "net/log/net_log_values.h"
#include "net/log/net_log_with_source.h"
#include "net/nqe/network_quality_estimator.h"
#include "net/proxy_resolution/proxy_info.h"
#include "net/proxy_resolution/proxy_resolution_service.h"
#include "net/proxy_resolution/proxy_retry_info.h"
#include "net/ssl/ssl_cert_request_info.h"
#include "net/ssl/ssl_config_service.h"
#include "net/ssl/ssl_connection_status_flags.h"
#include "net/storage_access_api/status.h"
#include "net/url_request/clear_site_data.h"
#include "net/url_request/redirect_util.h"
#include "net/url_request/url_request.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_factory.h"
#include "net/url_request/url_request_redirect_job.h"
#include "net/url_request/websocket_handshake_userdata_key.h"
#include "url/gurl.h"
#include "url/origin.h"
#include "url/url_constants.h"
#if BUILDFLAG(IS_ANDROID)
#include "net/android/network_library.h"
#endif
#if BUILDFLAG(ENABLE_DEVICE_BOUND_SESSIONS)
#include "net/device_bound_sessions/registration_fetcher_param.h"
#include "net/device_bound_sessions/session_service.h"
#endif
namespace {
enum class TpcdHeaderStatus { … };
void RecordTpcdHeaderStatus(TpcdHeaderStatus status) { … }
base::Value::Dict FirstPartySetMetadataNetLogParams(
const net::FirstPartySetMetadata& first_party_set_metadata,
const int64_t* const fps_cache_filter) { … }
base::Value::Dict CookieInclusionStatusNetLogParams(
const std::string& operation,
const std::string& cookie_name,
const std::string& cookie_domain,
const std::string& cookie_path,
const std::optional<net::CookiePartitionKey>& partition_key,
const net::CookieInclusionStatus& status,
net::NetLogCaptureMode capture_mode) { … }
void LogTrustAnchor(const net::HashValueVector& spki_hashes) { … }
net::CookieOptions CreateCookieOptions(
net::CookieOptions::SameSiteCookieContext same_site_context) { … }
bool IsTLS13OverTCP(const net::HttpResponseInfo& response_info) { … }
GURL UpgradeSchemeToCryptographic(const GURL& insecure_url) { … }
enum class ContentEncodingType { … };
bool IsSameSiteIgnoringWebSocketProtocol(const net::SchemefulSite& initiator,
const GURL& request_url) { … }
enum class HttpRequestStsState { … };
enum class HttpRequestSSLUpgradeDecision { … };
HttpRequestSSLUpgradeDecision GetMetricForSSLUpgradeDecision(
net::SSLUpgradeDecision upgrade_decision,
bool is_secure) { … }
void RecordSTSHistograms(net::SSLUpgradeDecision upgrade_decision,
bool is_secure,
int load_flags) { … }
char const* GetSecFetchStorageAccessHeaderValue(
net::cookie_util::StorageAccessStatus storage_access_status) { … }
}
namespace net {
std::unique_ptr<URLRequestJob> URLRequestHttpJob::Create(URLRequest* request) { … }
URLRequestHttpJob::URLRequestHttpJob(
URLRequest* request,
const HttpUserAgentSettings* http_user_agent_settings)
: … { … }
URLRequestHttpJob::~URLRequestHttpJob() { … }
void URLRequestHttpJob::SetPriority(RequestPriority priority) { … }
void URLRequestHttpJob::Start() { … }
namespace {
bool ShouldBlockAllCookies(PrivacyMode privacy_mode) { … }
}
void URLRequestHttpJob::MaybeSetSecFetchStorageAccessHeader() { … }
void URLRequestHttpJob::OnGotFirstPartySetMetadata(
FirstPartySetMetadata first_party_set_metadata,
FirstPartySetsCacheFilter::MatchInfo match_info) { … }
void URLRequestHttpJob::Kill() { … }
ConnectionAttempts URLRequestHttpJob::GetConnectionAttempts() const { … }
void URLRequestHttpJob::CloseConnectionOnDestruction() { … }
int URLRequestHttpJob::NotifyConnectedCallback(
const TransportInfo& info,
CompletionOnceCallback callback) { … }
PrivacyMode URLRequestHttpJob::DeterminePrivacyMode() const { … }
void URLRequestHttpJob::NotifyHeadersComplete() { … }
void URLRequestHttpJob::DestroyTransaction() { … }
void URLRequestHttpJob::StartTransaction() { … }
void URLRequestHttpJob::NotifyBeforeStartTransactionCallback(
int result,
const std::optional<HttpRequestHeaders>& headers) { … }
void URLRequestHttpJob::MaybeStartTransactionInternal(int result) { … }
void URLRequestHttpJob::StartTransactionInternal() { … }
void URLRequestHttpJob::AddExtraHeaders() { … }
void URLRequestHttpJob::AddCookieHeaderAndStart() { … }
void URLRequestHttpJob::SetCookieHeaderAndStart(
const CookieOptions& options,
const CookieAccessResultList& cookies_with_access_result_list,
const CookieAccessResultList& excluded_list) { … }
void URLRequestHttpJob::AnnotateAndMoveUserBlockedCookies(
CookieAccessResultList& maybe_included_cookies,
CookieAccessResultList& excluded_cookies) const { … }
void URLRequestHttpJob::SaveCookiesAndNotifyHeadersComplete(int result) { … }
void URLRequestHttpJob::OnSetCookieResult(const CookieOptions& options,
std::optional<CanonicalCookie> cookie,
std::string cookie_string,
CookieAccessResult access_result) { … }
#if BUILDFLAG(ENABLE_DEVICE_BOUND_SESSIONS)
void URLRequestHttpJob::ProcessDeviceBoundSessionsHeader() {
std::vector<device_bound_sessions::RegistrationFetcherParam> params =
device_bound_sessions::RegistrationFetcherParam::CreateIfValid(
request_->url(), GetResponseHeaders());
if (auto* service = request_->context()->device_bound_session_service()) {
for (auto& param : params) {
service->RegisterBoundSession(std::move(param),
request_->isolation_info());
}
}
}
#endif
void URLRequestHttpJob::ProcessStrictTransportSecurityHeader() { … }
void URLRequestHttpJob::OnStartCompleted(int result) { … }
void URLRequestHttpJob::OnHeadersReceivedCallback(int result) { … }
void URLRequestHttpJob::OnReadCompleted(int result) { … }
void URLRequestHttpJob::RestartTransactionWithAuth(
const AuthCredentials& credentials) { … }
void URLRequestHttpJob::SetUpload(UploadDataStream* upload) { … }
void URLRequestHttpJob::SetExtraRequestHeaders(
const HttpRequestHeaders& headers) { … }
LoadState URLRequestHttpJob::GetLoadState() const { … }
bool URLRequestHttpJob::GetMimeType(std::string* mime_type) const { … }
bool URLRequestHttpJob::GetCharset(std::string* charset) { … }
void URLRequestHttpJob::GetResponseInfo(HttpResponseInfo* info) { … }
void URLRequestHttpJob::GetLoadTimingInfo(
LoadTimingInfo* load_timing_info) const { … }
bool URLRequestHttpJob::GetTransactionRemoteEndpoint(
IPEndPoint* endpoint) const { … }
int URLRequestHttpJob::GetResponseCode() const { … }
void URLRequestHttpJob::PopulateNetErrorDetails(
NetErrorDetails* details) const { … }
std::unique_ptr<SourceStream> URLRequestHttpJob::SetUpSourceStream() { … }
cookie_util::StorageAccessStatus URLRequestHttpJob::StorageAccessStatus()
const { … }
bool URLRequestHttpJob::CopyFragmentOnRedirect(const GURL& location) const { … }
bool URLRequestHttpJob::IsSafeRedirect(const GURL& location) { … }
bool URLRequestHttpJob::NeedsAuth() { … }
bool URLRequestHttpJob::NeedsRetryWithStorageAccess() { … }
void URLRequestHttpJob::SetSharedDictionaryGetter(
SharedDictionaryGetter dictionary_getter) { … }
std::unique_ptr<AuthChallengeInfo> URLRequestHttpJob::GetAuthChallengeInfo() { … }
void URLRequestHttpJob::SetAuth(const AuthCredentials& credentials) { … }
void URLRequestHttpJob::CancelAuth() { … }
void URLRequestHttpJob::ContinueWithCertificate(
scoped_refptr<X509Certificate> client_cert,
scoped_refptr<SSLPrivateKey> client_private_key) { … }
void URLRequestHttpJob::ContinueDespiteLastError() { … }
bool URLRequestHttpJob::ShouldFixMismatchedContentLength(int rv) const { … }
int URLRequestHttpJob::ReadRawData(IOBuffer* buf, int buf_size) { … }
int64_t URLRequestHttpJob::GetTotalReceivedBytes() const { … }
int64_t URLRequestHttpJob::GetTotalSentBytes() const { … }
int64_t URLRequestHttpJob::GetReceivedBodyBytes() const { … }
void URLRequestHttpJob::DoneReading() { … }
void URLRequestHttpJob::DoneReadingRedirectResponse() { … }
void URLRequestHttpJob::DoneReadingRetryResponse() { … }
IPEndPoint URLRequestHttpJob::GetResponseRemoteEndpoint() const { … }
void URLRequestHttpJob::RecordTimer() { … }
void URLRequestHttpJob::ResetTimer() { … }
void URLRequestHttpJob::SetRequestHeadersCallback(
RequestHeadersCallback callback) { … }
void URLRequestHttpJob::SetEarlyResponseHeadersCallback(
ResponseHeadersCallback callback) { … }
void URLRequestHttpJob::SetIsSharedDictionaryReadAllowedCallback(
base::RepeatingCallback<bool()> callback) { … }
void URLRequestHttpJob::SetResponseHeadersCallback(
ResponseHeadersCallback callback) { … }
void URLRequestHttpJob::RecordCompletionHistograms(CompletionCause reason) { … }
void URLRequestHttpJob::DoneWithRequest(CompletionCause reason) { … }
HttpResponseHeaders* URLRequestHttpJob::GetResponseHeaders() const { … }
void URLRequestHttpJob::NotifyURLRequestDestroyed() { … }
bool URLRequestHttpJob::ShouldAddCookieHeader() const { … }
bool URLRequestHttpJob::ShouldRecordPartitionedCookieUsage() const { … }
}