cloudflare-soos 2.3.1

Helper tool for Cloudflare's enhanced HTTP/2 and HTTP/3 prioritization, which makes progressive images load faster. Supports JPEG, GIF, and PNG.
Documentation
use cloudflare_soos as soos;
use std::io::Read;
use std::io::Write;

fn main() {
    if let Err(e) = run() {
        let _ = writeln!(std::io::stderr().lock(), "error: {e}");
        std::process::exit(1);
    }
}

fn run() -> Result<(), soos::Error> {
    let mut args = std::env::args().skip(1);
    let input_file = if let Some(input_path) = args.next() {
        std::fs::read(input_path)?
    } else {
        let mut buf = Vec::with_capacity(0xFFFF);
        std::io::stdin().lock().read_to_end(&mut buf)?;
        buf
    };

    let is_rfc9218 = args.next().as_deref() == Some("--rfc9218");

    if is_rfc9218 {
        write!(std::io::stdout().lock(), "{}", soos::Scans::from_file(&input_file)?.rfc9218_priority_change_headers()?)?;
    } else {
        let (pri, pri_change) =
            soos::Scans::from_file(&input_file)?.cf_priority_change_headers()?;
        write!(std::io::stdout().lock(), "{pri}\n{pri_change}")?;
    }
    Ok(())
}