hatoo/oha · error · anyhow::Error

Unknown HTTP version. Valid versions are 0.9, 1.0, 1.1, 2, 3

Error message

Unknown HTTP version. Valid versions are 0.9, 1.0, 1.1, 2, 3

What it means

The --http-version option only accepts 0.9, 1.0, 1.1, 2/2.0, and 3/3.0. Any other string falls through the match to a catch-all bail listing the valid versions. This validates user CLI input before any network activity.

Solutions

  1. Use one of: 0.9, 1.0, 1.1, 2 (or 2.0), 3 (or 3.0).
  2. Note bare `2` and `3` are accepted alternatives to `2.0`/`3.0`.
  3. Check `oha --help` for the exact accepted values.

Example fix

// before
oha --http-version 1.2 https://example.com
// after
oha --http-version 1.1 https://example.com
Defensive patterns

Strategy: validation

Validate before calling

const VALID: [&str; 6] = ["0.9", "1.0", "1.1", "2", "2.0", "3"];
fn valid_http_version(v: &str) -> bool {
    VALID.contains(&v) || v == "3.0"
}

Try / catch

match run(opts).await {
    Err(e) if e.to_string().contains("Unknown HTTP version") => {
        eprintln!("Valid: 0.9, 1.0, 1.1, 2, 3");
    }
    Err(e) => return Err(e),
    Ok(v) => v,
}

Prevention

When it happens

Trigger: Passing an unrecognized version string such as `--http-version 1.2`, `--http-version http/1.1`, or a misspelled value like `--http-version 1,1`.

Common situations: Users typing versions with an 'HTTP/' prefix, using decimals like '1.2' that do not exist, or passing locale-formatted numbers.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


AI-assisted analysis of hatoo/oha@4efba2d113 (2026-09-09). Data as JSON: /api/errors/9e1b64ba11304078. Report an issue: GitHub.

Appendix: source

Thrown at src/main.rs:386

    } else {
        None
    };

    let parse_http_version = |is_http2: bool, version: Option<&str>| match (is_http2, version) {
        (true, Some(_)) => anyhow::bail!("--http2 and --http-version are exclusive"),
        (true, None) => Ok(http::Version::HTTP_2),
        (false, Some(http_version)) => match http_version.trim() {
            "0.9" => Ok(http::Version::HTTP_09),
            "1.0" => Ok(http::Version::HTTP_10),
            "1.1" => Ok(http::Version::HTTP_11),
            "2.0" | "2" => Ok(http::Version::HTTP_2),
            #[cfg(feature = "http3")]
            "3.0" | "3" => Ok(http::Version::HTTP_3),
            #[cfg(not(feature = "http3"))]
            "3.0" | "3" => anyhow::bail!(
                "Your Oha instance has not been built with HTTP/3 support. Try recompiling with the feature enabled."
            ),
            _ => anyhow::bail!("Unknown HTTP version. Valid versions are 0.9, 1.0, 1.1, 2, 3"),
        },
        (false, None) => Ok(http::Version::HTTP_11),
    };

    let http_version: http::Version = parse_http_version(opts.http2, opts.http_version.as_deref())?;
    let proxy_http_version: http::Version =
        parse_http_version(opts.proxy_http2, opts.proxy_http_version.as_deref())?;

    let url_generator = if opts.rand_regex_url {
        // Almost URL has dot in domain, so disable dot in regex for convenience.
        let dot_disabled: String = url
            .chars()
            .map(|c| {
                if c == '.' {
                    regex_syntax::escape(".")
                } else {
                    c.to_string()
                }

View on GitHub (pinned to 4efba2d113)