mirror of
https://github.com/tokio-rs/axum.git
synced 2024-11-22 15:17:18 +01:00
Serialize Json<T> to Bytes instead of Vec<u8> in IntoResponse (#1178)
This commit is contained in:
parent
a3eaa332e4
commit
a3cf025d54
1 changed files with 5 additions and 3 deletions
|
@ -5,6 +5,7 @@ use crate::{
|
|||
};
|
||||
use async_trait::async_trait;
|
||||
use axum_core::response::{IntoResponse, Response};
|
||||
use bytes::{BufMut, BytesMut};
|
||||
use http::{
|
||||
header::{self, HeaderValue},
|
||||
StatusCode,
|
||||
|
@ -185,13 +186,14 @@ where
|
|||
T: Serialize,
|
||||
{
|
||||
fn into_response(self) -> Response {
|
||||
match serde_json::to_vec(&self.0) {
|
||||
Ok(bytes) => (
|
||||
let mut buf = BytesMut::new().writer();
|
||||
match serde_json::to_writer(&mut buf, &self.0) {
|
||||
Ok(()) => (
|
||||
[(
|
||||
header::CONTENT_TYPE,
|
||||
HeaderValue::from_static(mime::APPLICATION_JSON.as_ref()),
|
||||
)],
|
||||
bytes,
|
||||
buf.into_inner().freeze(),
|
||||
)
|
||||
.into_response(),
|
||||
Err(err) => (
|
||||
|
|
Loading…
Reference in a new issue