scion-http3 0.8.2

High-level HTTP/3-over-SCION client: URL in, response out
Documentation

scion-http3

A high-level HTTP/3-over-SCION client: give it a URL, get a response.

use scion_http3::{Client, Config};

/// Cap on a collected response body; a larger one fails rather than buffering
/// unboundedly.
const MAX_BODY_SIZE: usize = 1 << 20;

async fn get_rooms() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new(
        Config::new("https://endhost-api.example.org".parse()?).with_auth_token("token"),
    );
    let response = client.get("https://chat.example.org/rooms").await?;
    let (body, _trailers) = response.text(Some(MAX_BODY_SIZE)).await?;
    println!("{body}");
    Ok(())
}

Client::connect opens an HTTP CONNECT tunnel and returns a byte stream:

use scion_http3::Authority;
use tokio::io::{AsyncReadExt, AsyncWriteExt};

async fn tunnel(client: &scion_http3::Client) -> Result<(), Box<dyn std::error::Error>> {
    let authority: Authority = "chat.example.org:443".parse()?;
    let mut tunnel = client.connect(&authority).await?;
    tunnel.write_all(b"hello").await?;
    let mut reply = vec![0u8; 5];
    tunnel.read_exact(&mut reply).await?;
    tunnel.shutdown().await?;
    Ok(())
}

Config::with_dns_override maps a host that has no TSAR records to fixed addresses. It applies to URLs and to CONNECT authorities alike.

See the crate documentation for the full API, and examples/http3_get_post.rs for a runnable end-to-end example against a local network:

cargo run -p scion-http3 --example http3_get_post