diff --git a/examples/impersonate_settings.rs b/examples/impersonate_settings.rs index 8fd4763d..53762747 100644 --- a/examples/impersonate_settings.rs +++ b/examples/impersonate_settings.rs @@ -6,7 +6,6 @@ use rquest::{ use rquest::{Client, ImpersonateSettings}; use rquest::{Http2Settings, PseudoOrder::*, SettingsOrder::*}; use rquest::{Priority, StreamDependency, StreamId}; -use std::borrow::Cow; // ============== TLS Extension Algorithms ============== @@ -119,7 +118,7 @@ async fn main() -> Result<(), rquest::Error> { .cipher_list(CIPHER_LIST) .sigalgs_list(SIGALGS_LIST) .delegated_credentials(DELEGATED_CREDENTIALS) - .cert_compression_algorithm(Cow::Borrowed(CERT_COMPRESSION_ALGORITHM)) + .cert_compression_algorithm(CERT_COMPRESSION_ALGORITHM) .record_size_limit(RECORD_SIZE_LIMIT) .alpn_protos(AlpnProtos::All) .alps_protos(AlpsProtos::Http2) diff --git a/src/imp/firefox.rs b/src/imp/firefox.rs index 51b75127..a685b76f 100644 --- a/src/imp/firefox.rs +++ b/src/imp/firefox.rs @@ -314,13 +314,13 @@ mod tls { .enable_ocsp_stapling(true) .enable_ech_grease(val.enable_ech_grease) .alpn_protos(AlpnProtos::All) - .cert_compression_algorithm(val.cert_compression_algorithm.map(Cow::Borrowed)) .min_tls_version(TlsVersion::TLS_1_2) .max_tls_version(TlsVersion::TLS_1_3) .key_shares_limit(val.key_shares_limit) .pre_shared_key(val.pre_shared_key) .psk_skip_session_ticket(val.psk_skip_session_tickets) .psk_dhe_ke(val.psk_dhe_ke) + .cert_compression_algorithm(val.cert_compression_algorithm) .extension_permutation_indices(val.extension_permutation_indices) .build() } diff --git a/src/tls/mod.rs b/src/tls/mod.rs index b142dd47..02fece4c 100644 --- a/src/tls/mod.rs +++ b/src/tls/mod.rs @@ -369,7 +369,7 @@ pub struct TlsSettings { pub sigalgs_list: Option>, /// Certificates in TLS 1.3 can be compressed [RFC 8879](https://datatracker.ietf.org/doc/html/rfc8879). - #[builder(default, setter(into))] + #[builder(default, setter(transform = |input: impl IntoCertCompressionAlgorithm| input.into()))] pub cert_compression_algorithm: Option>, /// Sets the context's extension permutation indices. @@ -413,3 +413,52 @@ impl_debug!( extension_permutation_indices } ); + +/// A trait for converting various types into an optional `Cow` containing a slice of `CertCompressionAlgorithm`. +/// +/// This trait is used to provide a unified way to convert different types +/// into an optional `Cow` containing a slice of `CertCompressionAlgorithm`. +pub trait IntoCertCompressionAlgorithm { + /// Converts the implementing type into an optional `Cow` containing a slice of `CertCompressionAlgorithm`. + fn into(self) -> Option>; +} + +/// Implements `IntoCertCompressionAlgorithm` for a static slice of `CertCompressionAlgorithm`. +/// +/// This implementation allows a static slice of `CertCompressionAlgorithm` to be converted +/// into an optional `Cow` containing a borrowed slice of `CertCompressionAlgorithm`. +impl IntoCertCompressionAlgorithm for &'static [CertCompressionAlgorithm] { + fn into(self) -> Option> { + Some(Cow::Borrowed(&self)) + } +} + +/// Implements `IntoCertCompressionAlgorithm` for a `Cow` containing a slice of `CertCompressionAlgorithm`. +/// +/// This implementation allows a `Cow` containing a slice of `CertCompressionAlgorithm` to be converted +/// into an optional `Cow` containing the same slice of `CertCompressionAlgorithm`. +impl IntoCertCompressionAlgorithm for Cow<'static, [CertCompressionAlgorithm]> { + fn into(self) -> Option> { + Some(self) + } +} + +/// Implements `IntoCertCompressionAlgorithm` for an optional static slice of `CertCompressionAlgorithm`. +/// +/// This implementation allows an optional static slice of `CertCompressionAlgorithm` to be converted +/// into an optional `Cow` containing a borrowed slice of `CertCompressionAlgorithm`. +impl IntoCertCompressionAlgorithm for Option<&'static [CertCompressionAlgorithm]> { + fn into(self) -> Option> { + self.map(Cow::Borrowed) + } +} + +/// Implements `IntoCertCompressionAlgorithm` for an optional `Cow` containing a slice of `CertCompressionAlgorithm`. +/// +/// This implementation allows an optional `Cow` containing a slice of `CertCompressionAlgorithm` to be converted +/// into an optional `Cow` containing the same slice of `CertCompressionAlgorithm`. +impl IntoCertCompressionAlgorithm for Option> { + fn into(self) -> Option> { + self + } +}