Skip to main content

specter/transport/h3/
command.rs

1use std::sync::Arc;
2
3use bytes::Bytes;
4use tokio::sync::oneshot;
5
6use crate::error::Result;
7use crate::headers::Headers;
8use crate::request::RequestBody;
9use crate::transport::h3::body::H3BodyShared;
10use crate::transport::h3::H3Tunnel;
11
12pub type StreamingHeadersResult = Result<(u16, Headers)>;
13
14/// Command sent from handle to driver.
15///
16/// Tunnel-data DATA frames do not flow through this control channel;
17/// they take a dedicated mpsc owned by the driver so a freshly issued
18/// streaming-request or tunnel-open is never queued behind a burst of
19/// in-flight RFC 9220 tunnel writes.
20#[derive(Debug)]
21pub enum DriverCommand {
22    /// Send a request and get response via oneshot.
23    SendRequest {
24        method: http::Method,
25        uri: http::Uri,
26        headers: Headers,
27        body: Option<Bytes>,
28        response_tx: oneshot::Sender<Result<StreamResponse>>,
29    },
30    /// Send a request and return headers as soon as they arrive, with DATA routed
31    /// incrementally through the body channel.
32    SendStreamingRequest {
33        method: http::Method,
34        uri: http::Uri,
35        headers: Headers,
36        body: RequestBody,
37        headers_tx: oneshot::Sender<StreamingHeadersResult>,
38        body_shared: Arc<H3BodyShared>,
39    },
40    /// Open an RFC 9220 WebSocket-over-HTTP/3 tunnel.
41    OpenWebSocketTunnel {
42        uri: http::Uri,
43        headers: Vec<(String, String)>,
44        response_tx: oneshot::Sender<Result<H3Tunnel>>,
45    },
46}
47
48#[derive(Debug)]
49pub struct StreamResponse {
50    pub status: u16,
51    pub headers: Vec<(String, String)>,
52    pub body: Bytes,
53}