Add content-type header to BRP HTTP responses (#15552)

This makes HTTP clients like httpie format the response as JSON rather
than text for a much nicer experience testing things.
This commit is contained in:
Liam Gallagher 2024-10-01 10:23:55 +13:00 committed by GitHub
parent 429987ebf8
commit 10068f4a26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,6 +19,7 @@ use core::net::{IpAddr, Ipv4Addr};
use http_body_util::{BodyExt as _, Full};
use hyper::{
body::{Bytes, Incoming},
header::HeaderValue,
server::conn::http1,
service, Request, Response,
};
@ -192,9 +193,12 @@ async fn process_request_batch(
}
};
Ok(Response::new(Full::new(Bytes::from(
serialized.as_bytes().to_owned(),
))))
let mut response = Response::new(Full::new(Bytes::from(serialized.as_bytes().to_owned())));
response.headers_mut().insert(
hyper::header::CONTENT_TYPE,
HeaderValue::from_static("application/json"),
);
Ok(response)
}
/// A helper function for the Bevy Remote Protocol server that processes a single