Fix Content-Type headers for {admin,k2v} errors and admin responses

Fix #315
This commit is contained in:
Alex Auvolat
2022-05-25 17:05:56 +02:00
parent 93eab8eaa3
commit ff06d3f082
8 changed files with 30 additions and 43 deletions
+9 -1
View File
@@ -1,4 +1,4 @@
use hyper::{Body, Request};
use hyper::{Body, Request, Response};
use idna::domain_to_unicode;
use serde::{Deserialize, Serialize};
@@ -144,6 +144,14 @@ pub async fn parse_json_body<T: for<'de> Deserialize<'de>>(req: Request<Body>) -
Ok(resp)
}
pub fn json_ok_response<T: Serialize>(res: &T) -> Result<Response<Body>, Error> {
let resp_json = serde_json::to_string_pretty(res).map_err(garage_util::error::Error::from)?;
Ok(Response::builder()
.status(hyper::StatusCode::OK)
.header(http::header::CONTENT_TYPE, "application/json")
.body(Body::from(resp_json))?)
}
#[cfg(test)]
mod tests {
use super::*;