hyper
hyper copied to clipboard
No `Connection: close` header in response by hyper server, when client sends it.
Version
axum = { version = "0.5.15" }
tokio = { version = "1.20", features = ["full"] }
Corresponding to Cargo.toml of axum, hyper = { version = "0.14.14" }
Platform Windows 10 Enterprise x64 (Os build: 19043.1889)
Description
Corresponding to Teardown section of RFC 7230, when client sends Connection: close header, server must close connection and response should contain that header.
[short summary of the bug]
I tried this code:
use axum::{routing::get, Router};
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello, World!" }));
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
}
So I've decided to check it with bare hyper, but result is the same:
use std::convert::Infallible;
use std::net::SocketAddr;
use hyper::{Body, Request, Response, Server};
use hyper::service::{make_service_fn, service_fn};
async fn hello_world(_req: Request<Body>) -> Result<Response<Body>, Infallible> {
Ok(Response::new("Hello, World".into()))
}
#[tokio::main]
async fn main() {
// We'll bind to 127.0.0.1:3000
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
// A `Service` is needed for every connection, so this
// creates one from our `hello_world` function.
let make_svc = make_service_fn(|_conn| async {
// service_fn converts our function into a `Service`
Ok::<_, Infallible>(service_fn(hello_world))
});
let server = Server::bind(&addr).serve(make_svc);
// Run this server for... forever!
if let Err(e) = server.await {
eprintln!("server error: {}", e);
}
}
I expected to see this happen:
Same setup with actix-web = "4.1"
use std::convert::Infallible;
use actix_web::{web, App, HttpResponse, HttpServer};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new().route(
"/",
web::get().to(|| async {
Ok::<_, Infallible>(HttpResponse::Ok().body("Hello, World!"))
}),
)
})
.bind(("127.0.0.1", 3000))?
.run()
.await
}
Screenshot of Actix web Instead, this happened: [explanation]
