mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-09 00:00:12 +02:00
axum-extra: Pre-allocate right sized buffer when encoding protobuf response (#3325)
This commit is contained in:
@@ -128,7 +128,7 @@ where
|
|||||||
T: Message + Default,
|
T: Message + Default,
|
||||||
{
|
{
|
||||||
fn into_response(self) -> Response {
|
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) {
|
match &self.0.encode(&mut buf) {
|
||||||
Ok(()) => buf.into_response(),
|
Ok(()) => buf.into_response(),
|
||||||
Err(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response(),
|
Err(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response(),
|
||||||
|
|||||||
Reference in New Issue
Block a user