Skip to content

Commit cbe2ab9

Browse files
committed
Merge branch 'simplify-response-check'
2 parents a78f9b4 + 177e232 commit cbe2ab9

File tree

3 files changed

+8
-21
lines changed

3 files changed

+8
-21
lines changed

core/src/response.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,22 @@ where
1919
{
2020
let response: Output = serde_json::from_slice(response_raw)
2121
.chain_err(|| ErrorKind::ResponseError("Not valid json"))?;
22+
ensure!(
23+
response.version() == Some(Version::V2),
24+
ErrorKind::ResponseError("Not JSON-RPC 2.0 compatible")
25+
);
26+
ensure!(
27+
response.id() == &expected_id,
28+
ErrorKind::ResponseError("Response id not equal to request id")
29+
);
2230
match response {
2331
Output::Success(success) => {
24-
check_response(success.jsonrpc, success.id, expected_id)?;
2532
trace!("Received json result: {}", success.result);
2633
serde_json::from_value::<R>(success.result)
2734
.chain_err(|| ErrorKind::ResponseError("Not valid for target type"))
2835
}
2936
Output::Failure(failure) => {
30-
check_response(failure.jsonrpc, failure.id, expected_id)?;
3137
Err(ErrorKind::JsonRpcError(failure.error).into())
3238
}
3339
}
3440
}
35-
36-
/// Validate if response is a valid JSON-RPC 2.0 response object with the correct Id.
37-
fn check_response(version: Option<Version>, id: Id, expected_id: Id) -> Result<()> {
38-
ensure!(
39-
version == Some(Version::V2),
40-
ErrorKind::ResponseError("Not JSON-RPC 2.0 compatible")
41-
);
42-
ensure!(
43-
id == expected_id,
44-
ErrorKind::ResponseError("Response id not equal to request id")
45-
);
46-
Ok(())
47-
}

http/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ default = ["tls"]
2525
tls = ["hyper-tls", "native-tls"]
2626

2727
[dev-dependencies]
28-
env_logger = "0.5"
2928
jsonrpc-core = "8.0"
3029
jsonrpc-macros = "8.0"
3130
jsonrpc-http-server = "8.0"

http/tests/localhost.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
extern crate env_logger;
109
extern crate futures;
1110
#[macro_use]
1211
extern crate jsonrpc_client_core;
@@ -48,8 +47,6 @@ jsonrpc_client!(pub struct TestClient {
4847

4948
#[test]
5049
fn localhost_ping_pong() {
51-
let _ = env_logger::init();
52-
5350
// Spawn a server hosting the `ServerApi` API.
5451
let (_server, uri) = spawn_server();
5552
println!("Testing towards server at {}", uri);
@@ -79,8 +76,6 @@ fn localhost_ping_pong() {
7976

8077
#[test]
8178
fn dropped_rpc_request_should_not_crash_transport() {
82-
let _ = env_logger::init();
83-
8479
let (_server, uri) = spawn_server();
8580

8681
let mut core = Core::new().unwrap();

0 commit comments

Comments
 (0)