From 8329c75ccf988497d6737a3f58c320c87f781173 Mon Sep 17 00:00:00 2001 From: Skye Date: Tue, 15 Aug 2023 21:44:57 +0900 Subject: [PATCH] turns out Bytes implements FromRequest --- flake.nix | 2 +- src/main.rs | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index 736f45e..7b015f1 100644 --- a/flake.nix +++ b/flake.nix @@ -28,7 +28,7 @@ path = ./.; }; - cargoSha256 = "sha256-6aA95Zm1FGp8xiv55QSBZFfmBXWz5pygc/8uQHvy3tM="; + cargoSha256 = "sha256-YZHQCFojC8Ch9jcyxXLKEVsMNtI4ufzbCPUPLbUkMCI="; }; in rec { packages = forAllSystems (s: let diff --git a/src/main.rs b/src/main.rs index c2c590c..ca6eb62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use std::fmt::Debug; use anyhow::Result; use axum::{ async_trait, - extract::{FromRef, FromRequestParts, Query, RawBody, State}, + extract::{FromRef, FromRequestParts, Query, State}, http::{header::AUTHORIZATION, request::Parts, HeaderValue, StatusCode}, response::{IntoResponse, Response}, routing::{delete, get, post}, @@ -14,7 +14,7 @@ use bb8::Pool; use bb8_redis::RedisConnectionManager; use hex::FromHex; use hyper::{ - body::to_bytes, + body::Bytes, header::{CONTENT_TYPE, ETAG, IF_NONE_MATCH}, Method, }; @@ -358,10 +358,9 @@ async fn delete_data( async fn set_data( AuthenticatedUser(id): AuthenticatedUser, RedisConnection(mut conn): RedisConnection, - RawBody(body): RawBody, + body: Bytes, ) -> Result, WrappedError> { let now = (OffsetDateTime::now_utc().unix_timestamp_nanos() / 1000) as u64; - let body = to_bytes(body).await?; redis::cmd("HSET") .arg(id) .arg("last_modified")