Skip to main content

spectreq/client/
http3.rs

1//! HTTP/3 (QUIC) support for Spectre client
2//!
3//! This module provides HTTP/3 over QUIC protocol support using
4//! the Quinn QUIC implementation and h3 HTTP/3 library.
5//!
6//! This feature requires the "http3" feature flag to be enabled.
7//!
8//! **NOTE**: The HTTP/3 implementation is currently experimental and
9//! may not work with all servers. The quinn/h3 API is evolving rapidly.
10
11use crate::core::{Profile, Result};
12
13/// Check if HTTP/3 is supported (ALPN h3 is available)
14pub fn supports_http3(tls_config: &rustls::ClientConfig) -> bool {
15    tls_config.alpn_protocols.iter().any(|p| p == b"h3")
16}
17
18/// Add h3 ALPN to TLS config for HTTP/3 support
19pub fn enable_http3(profile: &Profile) -> Result<Profile> {
20    let mut updated = profile.clone();
21    updated.tls.alpn.push("h3".to_string());
22    Ok(updated)
23}
24
25// HTTP/3 feature-gated types - stubs for API compatibility
26// Full implementation requires updating to latest quinn/h3 APIs
27
28#[cfg(feature = "http3")]
29pub type Http3Response = HttpResponse;
30
31#[cfg(feature = "http3")]
32#[derive(Debug, Clone)]
33pub struct HttpResponse {
34    pub status: u16,
35    pub headers: Vec<(String, String)>,
36    pub body: Vec<u8>,
37}
38
39#[cfg(test)]
40mod tests {
41    use super::*;
42
43    #[test]
44    fn test_enable_http3() {
45        let profile = Profile::chrome_143_windows();
46        let updated = enable_http3(&profile).unwrap();
47        assert!(updated.tls.alpn.contains(&"h3".to_string()));
48    }
49}