From 8d714d09a327249f16f77a8f5a160a2b7cfbf380 Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Fri, 26 Jan 2024 17:22:25 -0700 Subject: [PATCH] fix sync/async mismatch --- rpc-toolkit/src/cli.rs | 13 +++++++------ rpc-toolkit/src/handler/adapters.rs | 18 ++++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/rpc-toolkit/src/cli.rs b/rpc-toolkit/src/cli.rs index cdf62d7..cf050df 100644 --- a/rpc-toolkit/src/cli.rs +++ b/rpc-toolkit/src/cli.rs @@ -5,6 +5,7 @@ use std::time::Duration; use clap::{CommandFactory, FromArgMatches}; use imbl_value::Value; +use reqwest::header::{ACCEPT, CONTENT_LENGTH, CONTENT_TYPE}; use reqwest::{Client, Method}; use serde::de::DeserializeOwned; use serde::Serialize; @@ -101,25 +102,25 @@ pub async fn call_remote_http( let body; #[cfg(feature = "cbor")] { - req = req.header("content-type", "application/cbor"); - req = req.header("accept", "application/cbor, application/json"); + req = req.header(CONTENT_TYPE, "application/cbor"); + req = req.header(ACCEPT, "application/cbor, application/json"); body = serde_cbor::to_vec(&rpc_req)?; } #[cfg(not(feature = "cbor"))] { - req = req.header("content-type", "application/json"); - req = req.header("accept", "application/json"); + req = req.header(CONTENT_TYPE, "application/json"); + req = req.header(ACCEPT, "application/json"); body = serde_json::to_vec(&rpc_req)?; } let res = req - .header("content-length", body.len()) + .header(CONTENT_LENGTH, body.len()) .body(body) .send() .await?; match res .headers() - .get("content-type") + .get(CONTENT_TYPE) .and_then(|v| v.to_str().ok()) { Some("application/json") => { diff --git a/rpc-toolkit/src/handler/adapters.rs b/rpc-toolkit/src/handler/adapters.rs index 9fe71ed..7cf1fb1 100644 --- a/rpc-toolkit/src/handler/adapters.rs +++ b/rpc-toolkit/src/handler/adapters.rs @@ -650,14 +650,16 @@ where raw_params, }: HandlerArgsFor, ) -> Result { - self.handler.handle_sync(HandlerArgs { - context, - parent_method, - method, - params, - inherited_params: (self.inherit)(inherited_params.0, inherited_params.1), - raw_params, - }) + self.handler + .handle_async(HandlerArgs { + context, + parent_method, + method, + params, + inherited_params: (self.inherit)(inherited_params.0, inherited_params.1), + raw_params, + }) + .await } fn metadata( &self,