From 387faac6eccf535991e10456a321bd58c6457442 Mon Sep 17 00:00:00 2001 From: zys864 Date: Sun, 6 Feb 2022 18:59:22 +0800 Subject: [PATCH] update `axum` version to `0.4.5` --- ...\345\221\275\345\220\215-checkpoint.ipynb" | 6 +++ Cargo.lock | 40 +++++++++---------- Cargo.toml | 2 +- src/http/error.rs | 7 +--- src/http/extractor.rs | 15 ++++--- 5 files changed, 39 insertions(+), 31 deletions(-) create mode 100644 ".ipynb_checkpoints/\346\234\252\345\221\275\345\220\215-checkpoint.ipynb" diff --git "a/.ipynb_checkpoints/\346\234\252\345\221\275\345\220\215-checkpoint.ipynb" "b/.ipynb_checkpoints/\346\234\252\345\221\275\345\220\215-checkpoint.ipynb" new file mode 100644 index 0000000..363fcab --- /dev/null +++ "b/.ipynb_checkpoints/\346\234\252\345\221\275\345\220\215-checkpoint.ipynb" @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Cargo.lock b/Cargo.lock index 2ef74a7..2c84189 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -78,11 +78,12 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "axum" -version = "0.3.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b4e96976b2022b23b2199168ff9b281e9ddc1aa795607d5cb7146868ca5c101" +checksum = "1dbbc81d15ddf33148615b778836b525dbae4e0731710294b2c484e80c4858f7" dependencies = [ "async-trait", + "axum-core", "bitflags", "bytes", "futures-util", @@ -90,6 +91,7 @@ dependencies = [ "http-body", "hyper", "matchit", + "memchr", "mime", "percent-encoding", "pin-project-lite", @@ -100,11 +102,25 @@ dependencies = [ "tokio", "tokio-util", "tower", - "tower-http 0.1.2", + "tower-http", "tower-layer", "tower-service", ] +[[package]] +name = "axum-core" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ca6c0b218388a7ed6a8d25e94f7dea5498daaa4fd8c711fb3ff166041b06fda" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "mime", +] + [[package]] name = "base-x" version = "0.2.8" @@ -1110,7 +1126,7 @@ dependencies = [ "time", "tokio", "tower", - "tower-http 0.2.0", + "tower-http", "uuid", ] @@ -1710,22 +1726,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "tower-http" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f70061b0592867f0a60e67a6e699da5fe000c88a360a5b92ebdba9d73b2238c" -dependencies = [ - "bytes", - "futures-core", - "futures-util", - "http", - "http-body", - "pin-project", - "tower-layer", - "tower-service", -] - [[package]] name = "tower-http" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index ab6c208..e27b970 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ authors = [ # Core dependencies: runtime, HTTP framework and database client. futures = "0.3" tokio = { version = "1.14.0", features = ["macros", "rt-multi-thread"] } -axum = { version = "0.3.4", features = ["tower-log"] } +axum = { version = "0.4.5", features = ["tower-log"] } sqlx = { version = "0.5", features = ["runtime-tokio-native-tls", "postgres", "uuid", "time"] } # The `clap` beta gives us a much nicer way to define configuration parameters for our application. diff --git a/src/http/error.rs b/src/http/error.rs index ae21381..b5b808c 100644 --- a/src/http/error.rs +++ b/src/http/error.rs @@ -1,4 +1,4 @@ -use axum::body::{Bytes, Full, HttpBody}; +use axum::body::BoxBody; use axum::http::header::WWW_AUTHENTICATE; use axum::http::{HeaderMap, HeaderValue, Response, StatusCode}; use axum::response::IntoResponse; @@ -117,10 +117,7 @@ impl Error { /// By default, the generated `Display` impl is used to return a plaintext error message /// to the client. impl IntoResponse for Error { - type Body = Full; - type BodyError = as HttpBody>::Error; - - fn into_response(self) -> Response { + fn into_response(self) -> Response { match self { Self::UnprocessableEntity { errors } => { #[derive(serde::Serialize)] diff --git a/src/http/extractor.rs b/src/http/extractor.rs index d7a184b..aa6447d 100644 --- a/src/http/extractor.rs +++ b/src/http/extractor.rs @@ -1,5 +1,4 @@ use crate::http::error::Error; -use axum::body::Body; use axum::extract::{Extension, FromRequest, RequestParts}; use crate::http::ApiContext; @@ -147,10 +146,13 @@ impl MaybeAuthUser { // out of it that you couldn't write your own middleware for, except with a bunch of extra // boilerplate. #[async_trait] -impl FromRequest for AuthUser { +impl FromRequest for AuthUser +where + B: Send, +{ type Rejection = Error; - async fn from_request(req: &mut RequestParts) -> Result { + async fn from_request(req: &mut RequestParts) -> Result { let ctx: Extension = Extension::from_request(req) .await .expect("BUG: ApiContext was not added as an extension"); @@ -167,10 +169,13 @@ impl FromRequest for AuthUser { } #[async_trait] -impl FromRequest for MaybeAuthUser { +impl FromRequest for MaybeAuthUser +where + B: Send, +{ type Rejection = Error; - async fn from_request(req: &mut RequestParts) -> Result { + async fn from_request(req: &mut RequestParts) -> Result { let ctx: Extension = Extension::from_request(req) .await .expect("BUG: ApiContext was not added as an extension");