From fc15b41a37e123434ec39a277f107b78c1507bd8 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Tue, 26 Jan 2021 14:37:04 +0100 Subject: introduce SputnikParts::response_headers --- examples/csrf/src/main.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/csrf/src/main.rs b/examples/csrf/src/main.rs index 1048689..7259abd 100644 --- a/examples/csrf/src/main.rs +++ b/examples/csrf/src/main.rs @@ -33,11 +33,13 @@ async fn route(req: &mut Parts, body: Body) -> Result { } fn get_form(req: &mut Parts) -> Response { - let mut response = Builder::new(); - let csrf_input = req.csrf_token(&mut response).html_input(); - response.content_type(mime::TEXT_HTML).body( - format!("
- {}
", csrf_input).into() + Builder::new() + .content_type(mime::TEXT_HTML) + .body( + format!( + "
{}
", + req.csrf_token().html_input() + ).into() ).unwrap() } @@ -54,7 +56,12 @@ async fn post_form(req: &mut Parts, body: Body) -> Result { async fn service(req: hyper::Request) -> Result, Infallible> { let (mut parts, body) = req.into_parts(); match route(&mut parts, body).await { - Ok(res) => Ok(res), + Ok(mut res) => { + for (k,v) in parts.response_headers().iter() { + res.headers_mut().append(k, v.clone()); + } + Ok(res) + } Err(err) => { let (code, message) = render_error(err); // you can easily wrap or log errors here -- cgit v1.2.3