axum-extra: Pre-allocate right sized buffer when encoding protobuf response (#3325)

This commit is contained in:
Jake
2025-04-26 09:37:32 +02:00
committed by GitHub
parent 58f63bb4d0
commit 7b04b174b9
+1 -1
View File
@@ -128,7 +128,7 @@ where
T: Message + Default,
{
fn into_response(self) -> Response {
let mut buf = BytesMut::with_capacity(128);
let mut buf = BytesMut::with_capacity(self.0.encoded_len());
match &self.0.encode(&mut buf) {
Ok(()) => buf.into_response(),
Err(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response(),