diff --git a/api/src/handlers/chain_api.rs b/api/src/handlers/chain_api.rs index 91083867..af269d71 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 b42a92f1..31494a17 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 9bd58493..1bbf1a26 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