aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md18
1 files changed, 8 insertions, 10 deletions
diff --git a/README.md b/README.md
index 38bc5d8..9892e21 100644
--- a/README.md
+++ b/README.md
@@ -51,29 +51,27 @@ fn render_error(err: Error) -> (StatusCode, String) {
async fn route(req: &mut Parts, body: Body) -> Result<Response, Error> {
match (&req.method, req.uri.path()) {
- (&Method::GET, "/form") => get_form(req).await,
+ (&Method::GET, "/form") => Ok(get_form(req)),
(&Method::POST, "/form") => post_form(req, body).await,
_ => return Err(Error::NotFound("page not found".to_owned()))
}
}
-async fn get_form(req: &mut Parts) -> Result<Response, Error> {
+fn get_form(req: &mut Parts) -> Response {
let mut response = Builder::new();
- let csrf_token = req.csrf_token(&mut response);
- Ok(response.content_type(mime::TEXT_HTML).body(
+ let csrf_input = req.csrf_html_input(&mut response);
+ response.content_type(mime::TEXT_HTML).body(
format!("<form method=post>
- <input name=text>{}<button>Submit</button></form>", csrf_token.html_input()).into()
- ).unwrap())
+ <input name=text>{}<button>Submit</button></form>", csrf_input).into()
+ ).unwrap()
}
#[derive(Deserialize)]
struct FormData {text: String}
async fn post_form(req: &mut Parts, body: Body) -> Result<Response, Error> {
- let mut response = Builder::new();
- let csrf_token = req.csrf_token(&mut response);
- let msg: FormData = body.into_form_csrf(&csrf_token).await?;
- Ok(response.body(
+ let msg: FormData = body.into_form_csrf(req).await?;
+ Ok(Builder::new().body(
format!("hello {}", msg.text).into()
).unwrap())
}