Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update axum version to 0.4.5 #6

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .ipynb_checkpoints/未命名-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
40 changes: 20 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 2 additions & 5 deletions src/http/error.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Bytes>;
type BodyError = <Full<Bytes> as HttpBody>::Error;

fn into_response(self) -> Response<Self::Body> {
fn into_response(self) -> Response<BoxBody> {
match self {
Self::UnprocessableEntity { errors } => {
#[derive(serde::Serialize)]
Expand Down
15 changes: 10 additions & 5 deletions src/http/extractor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::http::error::Error;
use axum::body::Body;
use axum::extract::{Extension, FromRequest, RequestParts};

use crate::http::ApiContext;
Expand Down Expand Up @@ -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<B> FromRequest<B> for AuthUser
where
B: Send,
{
type Rejection = Error;

async fn from_request(req: &mut RequestParts<Body>) -> Result<Self, Self::Rejection> {
async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
let ctx: Extension<ApiContext> = Extension::from_request(req)
.await
.expect("BUG: ApiContext was not added as an extension");
Expand All @@ -167,10 +169,13 @@ impl FromRequest for AuthUser {
}

#[async_trait]
impl FromRequest for MaybeAuthUser {
impl<B> FromRequest<B> for MaybeAuthUser
where
B: Send,
{
type Rejection = Error;

async fn from_request(req: &mut RequestParts<Body>) -> Result<Self, Self::Rejection> {
async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
let ctx: Extension<ApiContext> = Extension::from_request(req)
.await
.expect("BUG: ApiContext was not added as an extension");
Expand Down