diff options
author | Martin Fischer <martin@push-f.com> | 2021-04-18 10:42:14 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-04-18 10:42:14 +0200 |
commit | e731a5f94e1062cb62c2f8e9e123aee528b322ac (patch) | |
tree | fb2f25370e170564a53c93d246c3ca556ed88a21 /README.md | |
parent | d6b193f4adc29421901d7a27e3fba33dd6b14978 (diff) |
add html_escape methodv0.4.1
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -32,7 +32,7 @@ Protect your application against [CSRF](https://en.wikipedia.org/wiki/Cross-site by setting `SameSite` to `Lax` or `Strict` for your cookies and checking that the `Origin` header matches your domain name (especially if you have unauthenticated POST endpoints). -## Example +## Hyper Example ```rust use std::convert::Infallible; @@ -41,7 +41,7 @@ use hyper::{Method, Server, StatusCode, Body}; use hyper::http::request::Parts; use hyper::http::response::Builder; use serde::Deserialize; -use sputnik::{mime, request::SputnikParts, response::SputnikBuilder}; +use sputnik::{html_escape, mime, request::SputnikParts, response::SputnikBuilder}; use sputnik::hyper_body::{SputnikBody, FormError}; type Response = hyper::Response<Body>; @@ -82,8 +82,8 @@ struct FormData {text: String} async fn post_form(_req: &mut Parts, body: Body) -> Result<Response, Error> { let msg: FormData = body.into_form().await?; - Ok(Builder::new().body( - format!("hello {}", msg.text).into() + Ok(Builder::new().content_type(mime::TEXT_HTML).body( + format!("hello <em>{}</em>", html_escape(msg.text)).into() ).unwrap()) } |