Repository: servo/servo
File: components/net/connector.rs (Rust)

Code before:
    }
}

#[derive(Debug)]
struct CertificateVerificationOverrideVerifier {
    main_verifier: Arc<dyn ServerCertVerifier>,
    ignore_certificate_errors: bool,
    override_manager: CertificateErrorOverrideManager,
}

impl CertificateVerificationOverrideVerifier {
    fn new(
        ca_certficates: CACertificates<'static>,
        ignore_certificate_errors: bool,
        override_manager: CertificateErrorOverrideManager,
    ) -> Self {
        // From <https://github.com/rustls/rustls-platform-verifier/blob/main/README.md>:
        // > Some manual setup is required, outside of cargo, to use this crate on
        // > Android. In order to use Android's certificate verifier, the crate needs to
        // > call into the JVM. A small Kotlin component must be included in your app's
        // > build to support rustls-platform-verifier.
        //
        // Since we cannot count on embedders to do this setup, just stick with webpki roots
        // on Android.
        let use_platform_verifier =
            !cfg!(target_os = "android") || !pref!(network_use_webpki_roots);

        let main_verifier = if use_platform_verifier {
            let crypto_provider = CryptoProvider::get_default()
                .unwrap_or(&Arc::new(aws_lc_rs::default_provider()))
                .clone();
            let verifier = match ca_certficates {
                CACertificates::Default => rustls_platform_verifier::Verifier::new(crypto_provider),
                // Android doesn't support `Verifier::new_with_extra_roots`, but currently Android
                // never uses the platform verifier at all.
                #[cfg(target_os = "android")]
                CACertificates::Override(..) => {
                    rustls_platform_verifier::Verifier::new(crypto_provider)
                },
                #[cfg(not(target_os = "android"))]
                CACertificates::Override(certificates) => {
                    rustls_platform_verifier::Verifier::new_with_extra_roots(
                        certificates,
                        crypto_provider,
                    )
                },
            }
            .expect("Could not initialize platform certificate verifier");
            Arc::new(verifier) as Arc<dyn ServerCertVerifier>
        } else {
            let mut root_store =

Review comment (suggestion):
Should this be 
```
 !cfg!(target_os = "android") && !pref!(network_use_webpki_roots);
```

Otherwise we allow the value of `network_use_webpki_roots` to decide which verifier to use on Android.

Code after:
        ProtocolVersion::DTLSv1_0 => "DTLS 1.0".to_string(),
        ProtocolVersion::DTLSv1_2 => "DTLS 1.2".to_string(),
        ProtocolVersion::DTLSv1_3 => "DTLS 1.3".to_string(),
        ProtocolVersion::Unknown(v) => format!("Unknown(0x{v:04x})"),
        _ => format!("{version:?}"),
    }
}

impl<T> InstrumentedStream<T>
where
    T: Connection + hyper::rt::Read + hyper::rt::Write + Unpin,
{
    fn from_maybe_https_stream(stream: MaybeHttpsStream<T>) -> Self {
        match stream {
            MaybeHttpsStream::Http(inner) => Self {
                inner: MaybeHttpsStream::Http(inner),
                tls_info: None,
            },
            MaybeHttpsStream::Https(tls_stream) => {
                let (_tcp, tls) = tls_stream.inner().get_ref();
                let tls_info = TlsHandshakeInfo::from_connection(tls);

                Self {
                    inner: MaybeHttpsStream::Https(tls_stream),
                    tls_info: Some(tls_info),
                }
            },
        }
    }
}

impl<T> Connection for InstrumentedStream<T>
where
    T: Connection + hyper::rt::Read + hyper::rt::Write + Unpin,
{
    fn connected(&self) -> Connected {
        let connected = match &self.inner {
            MaybeHttpsStream::Http(stream) => stream.connected(),
            MaybeHttpsStream::Https(stream) => {
                let (tcp, tls) = stream.inner().get_ref();
                if tls.alpn_protocol() == Some(ALPN_H2.as_bytes()) {
                    tcp.inner().connected().negotiated_h2()
                } else {
                    tcp.inner().connected()
                }
            },
        };
        if let Some(info) = &self.tls_info {
            connected.extra(info.clone())
        } else {
            connected