Skip to content

Commit 0a0d0f8

Browse files
committed
Don't prettify run result json
1 parent e83beb4 commit 0a0d0f8

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

src/docker_run/api/mod.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,24 @@ pub struct SuccessResponse {
108108
body: Vec<u8>,
109109
}
110110

111+
pub enum JsonFormat {
112+
Minimal,
113+
Pretty,
114+
}
115+
116+
117+
pub fn prepare_json_response<T: serde::Serialize>(body: &T, format: JsonFormat) -> Result<SuccessResponse, ErrorResponse> {
118+
let json_to_vec = match format {
119+
JsonFormat::Minimal => {
120+
serde_json::to_vec
121+
}
122+
123+
JsonFormat::Pretty => {
124+
serde_json::to_vec_pretty
125+
}
126+
};
111127

112-
pub fn prepare_json_response<T: serde::Serialize>(body: &T) -> Result<SuccessResponse, ErrorResponse> {
113-
match serde_json::to_vec_pretty(body) {
128+
match json_to_vec(body) {
114129
Ok(data) => {
115130
Ok(SuccessResponse{
116131
status_code: 200,

src/docker_run/api/root.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ pub fn handle(_: &config::Config, _: &mut tiny_http::Request) -> Result<api::Suc
1818
name: "docker-run".to_string(),
1919
version: VERSION.unwrap_or("unknown").to_string(),
2020
description: "Api for running code in transient docker containers".to_string(),
21-
})
21+
}, api::JsonFormat::Pretty)
2222
}

src/docker_run/api/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn handle(config: &config::Config, request: &mut tiny_http::Request) -> Resu
2424
limits: config.run.clone(),
2525
}).map_err(handle_error)?;
2626

27-
api::prepare_json_response(&run_result)
27+
api::prepare_json_response(&run_result, api::JsonFormat::Minimal)
2828
}
2929

3030
fn handle_error(err: run::Error) -> api::ErrorResponse {

src/docker_run/api/version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn handle(config: &config::Config, request: &mut tiny_http::Request) -> Resu
1818
let data = get_version_info(&config.unix_socket)
1919
.map_err(handle_error)?;
2020

21-
api::prepare_json_response(&data)
21+
api::prepare_json_response(&data, api::JsonFormat::Pretty)
2222
}
2323

2424

0 commit comments

Comments
 (0)