Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I cannot extract the TypedHeader<Host> using http2 #1915

Closed
1 task done
philippgl opened this issue Apr 6, 2023 · 0 comments
Closed
1 task done

I cannot extract the TypedHeader<Host> using http2 #1915

philippgl opened this issue Apr 6, 2023 · 0 comments

Comments

@philippgl
Copy link

  • I have looked for existing issues (including closed) about this

Bug Report

Version

24f8dc5 (head)

Platform

Linux lab-phgl 6.2.9-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 30 Mar 2023 14:51:14 +0000 x86_64 GNU/Linux

Crates

Cargo.tom:

[package]
name = "example-bug"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
axum = { path = "../../axum", features = ["headers", "http2" ] }
tokio = { version = "1.0", features = ["full"] }

Description

I cannot extract the host header (I have not tried other headers), if using http2. i needed to use --http2-prior-knowledge or https (using the axum-server crate).

curl --http2 --http2-prior-knowledge -v 'http://localhost:3000/'

works, but

curl --http2 --http2-prior-knowledge -v 'http://localhost:3000/host'

breaks.

I tried this code:

use std::net::SocketAddr;

use axum::{extract::TypedHeader, headers::Host, routing::get, Router};

#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/host", get(host_handler))
        .route("/", get(|| async { "static reply" }));
    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
    let server = axum::Server::bind(&addr);
    server.serve(app.into_make_service()).await.unwrap();
}

async fn host_handler(TypedHeader(host): TypedHeader<Host>) -> String {
    format!("connected to {}", host.hostname())
}

I expected to see this happen:

With the above curl command, I expect:

connected to localhost

(status 200)

Instead, this happened:

Header of type `host` was missing

(status 400)

@tokio-rs tokio-rs locked and limited conversation to collaborators Apr 6, 2023
@davidpdrsn davidpdrsn converted this issue into discussion #1916 Apr 6, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant