1 // Copyright 2024 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_HTTP_HTTP_STREAM_KEY_H_ 6 #define NET_HTTP_HTTP_STREAM_KEY_H_ 7 8 #include <optional> 9 #include <string> 10 11 #include "base/values.h" 12 #include "net/base/net_export.h" 13 #include "net/base/network_anonymization_key.h" 14 #include "net/base/privacy_mode.h" 15 #include "net/dns/public/secure_dns_policy.h" 16 #include "net/quic/quic_session_alias_key.h" 17 #include "net/quic/quic_session_key.h" 18 #include "net/socket/socket_tag.h" 19 #include "net/spdy/spdy_session_key.h" 20 #include "url/scheme_host_port.h" 21 22 namespace net { 23 24 // The key used to group HttpStreams that don't require proxies. 25 // Currently SocketTag is not supported. 26 // TODO(crbug.com/346835898): Support SocketTag. 27 class NET_EXPORT_PRIVATE HttpStreamKey { 28 public: 29 HttpStreamKey(); 30 HttpStreamKey(url::SchemeHostPort destination, 31 PrivacyMode privacy_mode, 32 SocketTag socket_tag, 33 NetworkAnonymizationKey network_anonymization_key, 34 SecureDnsPolicy secure_dns_policy, 35 bool disable_cert_network_fetches); 36 37 ~HttpStreamKey(); 38 39 HttpStreamKey(const HttpStreamKey& other); 40 HttpStreamKey& operator=(const HttpStreamKey& other); 41 42 bool operator==(const HttpStreamKey& other) const; 43 bool operator<(const HttpStreamKey& other) const; 44 destination()45 const url::SchemeHostPort& destination() const { return destination_; } 46 privacy_mode()47 PrivacyMode privacy_mode() const { return privacy_mode_; } 48 socket_tag()49 const SocketTag& socket_tag() const { return socket_tag_; } 50 network_anonymization_key()51 const NetworkAnonymizationKey& network_anonymization_key() const { 52 return network_anonymization_key_; 53 } 54 secure_dns_policy()55 SecureDnsPolicy secure_dns_policy() const { return secure_dns_policy_; } 56 disable_cert_network_fetches()57 bool disable_cert_network_fetches() const { 58 return disable_cert_network_fetches_; 59 } 60 61 std::string ToString() const; 62 63 base::Value::Dict ToValue() const; 64 65 // Calculate a SpdySessionKey from `this`. Unlike 66 // CalculateQuicSessionAliasKey(), this method doesn't take an optional 67 // destination because we don't use a different destination for 68 // SpdySessionKey. 69 // TODO(crbug.com/346835898): We may need to create SpdySessionAliasKey and 70 // use a different destination to support H2 alternative endpoints that have 71 // different destinations. Returns a key with an empty host when the scheme is 72 // not cryptographic. 73 SpdySessionKey CalculateSpdySessionKey() const; 74 75 // Calculates a QuicSessionAliasKey from `this`. When 76 // `optional_alias_name` is provided, use the destination as the destination 77 // of QuicSessionAliasKey. See the comment of QuicSessionAliasKey about the 78 // difference between the server id and the destination. Returns a key with 79 // empty server_id/destination when the scheme is not cryptographic. 80 QuicSessionAliasKey CalculateQuicSessionAliasKey( 81 std::optional<url::SchemeHostPort> optional_alias_name = 82 std::nullopt) const; 83 84 private: 85 url::SchemeHostPort destination_; 86 PrivacyMode privacy_mode_ = PrivacyMode::PRIVACY_MODE_DISABLED; 87 SocketTag socket_tag_; 88 NetworkAnonymizationKey network_anonymization_key_; 89 SecureDnsPolicy secure_dns_policy_ = SecureDnsPolicy::kAllow; 90 bool disable_cert_network_fetches_ = false; 91 }; 92 93 } // namespace net 94 95 #endif // NET_HTTP_HTTP_STREAM_KEY_H_ 96