aboutsummaryrefslogtreecommitdiff
path: root/src/routes.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes.rs')
-rw-r--r--src/routes.rs25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/routes.rs b/src/routes.rs
index ef63c8e..ae87d39 100644
--- a/src/routes.rs
+++ b/src/routes.rs
@@ -1,4 +1,6 @@
-use hyper::{Body, Method, Request, Response};
+use http_body_util::{BodyExt, Full};
+use hyper::body::{Bytes, Incoming};
+use hyper::{Method, Request, Response};
use serde::Deserialize;
use sqlx::sqlite::SqlitePool;
use std::collections::HashMap;
@@ -19,8 +21,8 @@ pub async fn routes(
pool: SqlitePool,
assets: HashMap<String, String>,
templates: Tera,
- request: Request<Body>,
-) -> Result<Response<Body>, Infallible> {
+ request: Request<Incoming>,
+) -> Result<Response<Full<Bytes>>, Infallible> {
let method = request.method();
let uri = request.uri();
let path = &uri.path().split('/').collect::<Vec<&str>>()[1..];
@@ -68,7 +70,7 @@ pub async fn routes(
async fn connected_user(
config: &Config,
pool: &SqlitePool,
- request: &Request<Body>,
+ request: &Request<Incoming>,
) -> Option<User> {
let cookie = request.headers().get("COOKIE")?.to_str().ok()?;
let login_token = cookie::extract_token(config, cookie).ok()?;
@@ -78,8 +80,8 @@ async fn connected_user(
async fn authenticated_routes(
config: &Config,
wallet: Wallet,
- request: Request<Body>,
-) -> Response<Body> {
+ request: Request<Incoming>,
+) -> Response<Full<Bytes>> {
let method = request.method();
let uri = request.uri();
let path = &uri.path().split('/').collect::<Vec<&str>>()[1..];
@@ -202,7 +204,7 @@ async fn authenticated_routes(
_ => controller::error::error(
&wallet,
"Page introuvable",
- "La page que recherchez n’existe pas.",
+ "La page que vous recherchez n’existe pas.",
),
}
}
@@ -211,9 +213,12 @@ fn parse_query<'a, T: Deserialize<'a>>(query: Option<&'a str>) -> T {
serde_urlencoded::from_str(query.unwrap_or("")).unwrap()
}
-async fn body_form(request: Request<Body>) -> HashMap<String, String> {
- match hyper::body::to_bytes(request).await {
- Ok(bytes) => form_urlencoded::parse(bytes.as_ref())
+async fn body_form(request: Request<Incoming>) -> HashMap<String, String> {
+ match request.collect().await {
+ // Warning: this is a simplified use case. In principle names can appear multiple times in
+ // a form, and the values should be rolled up into a HashMap<String, Vec<String>>. However
+ // in this example the simpler approach is sufficient.
+ Ok(content) => form_urlencoded::parse(content.to_bytes().as_ref())
.into_owned()
.collect::<HashMap<String, String>>(),
Err(_) => HashMap::new(),