From 584c328bb058e9347f665214080548d88f35c9e8 Mon Sep 17 00:00:00 2001 From: Fujiwara Takumi Date: Sun, 17 Dec 2023 19:35:46 +0800 Subject: [PATCH] Unnecessary BytesMut (#2414) Co-authored-by: David Pedersen --- axum/src/extract/raw_form.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/axum/src/extract/raw_form.rs b/axum/src/extract/raw_form.rs index f9c7d357..a4e0d6c5 100644 --- a/axum/src/extract/raw_form.rs +++ b/axum/src/extract/raw_form.rs @@ -1,6 +1,6 @@ use async_trait::async_trait; use axum_core::extract::{FromRequest, Request}; -use bytes::{Bytes, BytesMut}; +use bytes::Bytes; use http::Method; use super::{ @@ -39,13 +39,11 @@ where async fn from_request(req: Request, state: &S) -> Result { if req.method() == Method::GET { - let mut bytes = BytesMut::new(); - 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 { if !has_content_type(req.headers(), &mime::APPLICATION_WWW_FORM_URLENCODED) { return Err(InvalidFormContentType.into());