Unnecessary BytesMut (#2414)

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
This commit is contained in:
Fujiwara Takumi 2023-12-17 19:35:46 +08:00 committed by GitHub
parent 72ccde5900
commit 584c328bb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,6 @@
use async_trait::async_trait; use async_trait::async_trait;
use axum_core::extract::{FromRequest, Request}; use axum_core::extract::{FromRequest, Request};
use bytes::{Bytes, BytesMut}; use bytes::Bytes;
use http::Method; use http::Method;
use super::{ use super::{
@ -39,13 +39,11 @@ where
async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> { async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> {
if req.method() == Method::GET { if req.method() == Method::GET {
let mut bytes = BytesMut::new();
if let Some(query) = req.uri().query() { if let Some(query) = req.uri().query() {
bytes.extend(query.as_bytes()); return Ok(Self(Bytes::copy_from_slice(query.as_bytes())));
} }
Ok(Self(bytes.freeze())) Ok(Self(Bytes::new()))
} else { } else {
if !has_content_type(req.headers(), &mime::APPLICATION_WWW_FORM_URLENCODED) { if !has_content_type(req.headers(), &mime::APPLICATION_WWW_FORM_URLENCODED) {
return Err(InvalidFormContentType.into()); return Err(InvalidFormContentType.into());