diff options
author | Martin Fischer <martin@push-f.com> | 2021-01-26 14:37:04 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-01-26 15:48:17 +0100 |
commit | fc15b41a37e123434ec39a277f107b78c1507bd8 (patch) | |
tree | 78d450bc04ef64e59a636a37c2147ec9bffba40c /examples/csrf | |
parent | 8e9a4400ea9bcb80c90232fecc2ad2ae5f6c3303 (diff) |
introduce SputnikParts::response_headers
Diffstat (limited to 'examples/csrf')
-rw-r--r-- | examples/csrf/src/main.rs | 19 |
1 files changed, 13 insertions, 6 deletions
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<Response, Error> { } 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!("<form method=post> - <input name=text>{}<button>Submit</button></form>", csrf_input).into() + Builder::new() + .content_type(mime::TEXT_HTML) + .body( + format!( + "<form method=post><input name=text>{}<button>Submit</button></form>", + req.csrf_token().html_input() + ).into() ).unwrap() } @@ -54,7 +56,12 @@ async fn post_form(req: &mut Parts, body: Body) -> Result<Response, Error> { async fn service(req: hyper::Request<hyper::Body>) -> Result<hyper::Response<hyper::Body>, 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 |