From 3b74a9ba3f77fd0e20234614b16040d9bfccbae7 Mon Sep 17 00:00:00 2001 From: Mark Renten <42224876+rentenmark@users.noreply.github.com> Date: Mon, 11 Feb 2019 13:54:21 -0500 Subject: [PATCH] Add content disposition for OK responses (#2545) --- api/src/handlers/chain_api.rs | 4 ++-- api/src/handlers/peers_api.rs | 2 +- wallet/src/controller.rs | 23 +++++++++++++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/api/src/handlers/chain_api.rs b/api/src/handlers/chain_api.rs index 910838671..af269d71f 100644 --- a/api/src/handlers/chain_api.rs +++ b/api/src/handlers/chain_api.rs @@ -56,7 +56,7 @@ pub struct ChainValidationHandler { impl Handler for ChainValidationHandler { fn get(&self, _req: Request
) -> ResponseFuture { match w(&self.chain).validate(true) { - Ok(_) => response(StatusCode::OK, ""), + Ok(_) => response(StatusCode::OK, "{}"), Err(e) => response( StatusCode::INTERNAL_SERVER_ERROR, format!("validate failed: {}", e), @@ -75,7 +75,7 @@ pub struct ChainCompactHandler { impl Handler for ChainCompactHandler { fn post(&self, _req: Request) -> ResponseFuture { match w(&self.chain).compact() { - Ok(_) => response(StatusCode::OK, ""), + Ok(_) => response(StatusCode::OK, "{}"), Err(e) => response( StatusCode::INTERNAL_SERVER_ERROR, format!("compact failed: {}", e), diff --git a/api/src/handlers/peers_api.rs b/api/src/handlers/peers_api.rs index b42a92f1b..31494a17c 100644 --- a/api/src/handlers/peers_api.rs +++ b/api/src/handlers/peers_api.rs @@ -97,6 +97,6 @@ impl Handler for PeerHandler { _ => return response(StatusCode::BAD_REQUEST, "invalid command"), }; - response(StatusCode::OK, "") + response(StatusCode::OK, "{}") } } diff --git a/wallet/src/controller.rs b/wallet/src/controller.rs index 9bd584932..1bbf1a268 100644 --- a/wallet/src/controller.rs +++ b/wallet/src/controller.rs @@ -487,11 +487,11 @@ where ), "cancel_tx" => Box::new( self.cancel_tx(req, api) - .and_then(|_| ok(response(StatusCode::OK, ""))), + .and_then(|_| ok(response(StatusCode::OK, "{}"))), ), "post_tx" => Box::new( self.post_tx(req, api) - .and_then(|_| ok(response(StatusCode::OK, ""))), + .and_then(|_| ok(response(StatusCode::OK, "{}"))), ), _ => Box::new(err(ErrorKind::GenericError( "Unknown error handling post request".to_owned(), @@ -677,20 +677,31 @@ fn create_ok_response(json: &str) -> Response { "access-control-allow-headers", "Content-Type, Authorization", ) + .header(hyper::header::CONTENT_TYPE, "application/json") .body(json.to_string().into()) .unwrap() } +/// Build a new hyper Response with the status code and body provided. +/// +/// Whenever the status code is `StatusCode::OK` the text parameter should be +/// valid JSON as the content type header will be set to `application/json' fn response