Tide: req.version() is always None instead of Some(http_types::Version::Http1_1)

Created on 31 Jul 2020  ·  4Comments  ·  Source: http-rs/tide

Bug Report

I want to retreive the HTTP version information, so that I can use it programmatically for tracing information (OpenTelemetry).
Due to the unexpected None I have to assume 1.1, but I wish that tide could return the current and correct version information, so that in a potential future with multiple version support the data is present and reliable.

I tried to go down the rabbit hole but got lost, so I hope the community and maintainers have more luck.

Current Behavior

cargo run --release
    Finished release [optimized] target(s) in 1.73s
     Running `target/release/tidetest`
{"level":30,"time":1596213036227,"msg":"Logger started","level":Info}
{"level":30,"time":1596213036227,"msg":"Server listening on http://127.0.0.1:8080"}
{"level":30,"time":1596213058722,"msg":"<-- Request received","method":GET,"path":/}
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `None`,
 right: `Some(Http1_1)`', src/main.rs:8:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

triggered via calling the server:

curl http://localhost:8080/ -i
curl: (52) Empty reply from server

Code/Gist

Replicating the code snippet from the documentation:

use tide::Request;

#[async_std::main]
async fn main() -> Result<(), std::io::Error> {
    tide::log::start();
    let mut app = tide::new();
    app.at("/").get(|req: Request<()>| async move {
        assert_eq!(req.version(), Some(http_types::Version::Http1_1));
        Ok("")
    });
    app.listen("127.0.0.1:8080").await?;

    Ok(())
}
Cargo.toml
# ...

[dependencies]
async-std = {version =  "1.6", features = ["attributes"]}
femme = "2.1"
tide = "0.12"
http-types = "2.2.1" # using the exact version of tide 0.12, but also fails with latest

Expected behavior/code

req.version() shall return Some(http_types::Version::Http1_1) as the documentation suggests and users would expect.

Environment

  • Rust toolchain version(s):

    • Windows 10: stable-x86_64-pc-windows-msvc

    • Debian 9.12: stable-x86_64-unknown-linux-gnu

  • OS: Windows 10 and Debian 9.12 (WSL2)
  • Possible Solution

    _No idea._ 🤷🏻‍♂️

    Additional context/Screenshots

    bug

    All 4 comments

    Published async-h1 v2.1.2 which includes @jbr's fix. Running cargo update on your repo should fix this issue!

    [patch.crates-io]
    async-h1 = { git = "https://github.com/http-rs/async-h1" }
    

    This works.

    Crate version doesn't seem to be published to crates.io yet. Can you publish it there as well? Thank you! 🙇🏻‍♂️

    Also thank you for the very quick fix and turnaround. You're all awesome! 💙

    @asaaki oops; you're right. It should work now!

    Can confirm, all good now! ✨

    Was this page helpful?
    0 / 5 - 0 ratings

    Related issues

    Nemo157 picture Nemo157  ·  6Comments

    kamyuentse picture kamyuentse  ·  4Comments

    friktor picture friktor  ·  3Comments

    cquintana-verbio picture cquintana-verbio  ·  6Comments

    tirr-c picture tirr-c  ·  6Comments