1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 14:49:20 +02:00

Remove extensions from head (#2487)

This commit is contained in:
Rob Ede
2021-12-08 22:58:50 +00:00
committed by GitHub
parent 07f2fe385b
commit 7dc034f0fb
12 changed files with 96 additions and 65 deletions

View File

@ -1,8 +1,9 @@
use std::{convert::Infallible, io};
use actix_http::{HttpService, Response, StatusCode};
use actix_http::{
header::HeaderValue, HttpMessage, HttpService, Request, Response, StatusCode,
};
use actix_server::Server;
use http::header::HeaderValue;
#[actix_rt::main]
async fn main() -> io::Result<()> {
@ -13,12 +14,21 @@ async fn main() -> io::Result<()> {
HttpService::build()
.client_timeout(1000)
.client_disconnect(1000)
.finish(|req| async move {
.on_connect_ext(|_, ext| {
ext.insert(42u32);
})
.finish(|req: Request| async move {
log::info!("{:?}", req);
let mut res = Response::build(StatusCode::OK);
res.insert_header(("x-head", HeaderValue::from_static("dummy value!")));
let forty_two = req.extensions().get::<u32>().unwrap().to_string();
res.insert_header((
"x-forty-two",
HeaderValue::from_str(&forty_two).unwrap(),
));
Ok::<_, Infallible>(res.body("Hello world!"))
})
.tcp()