mirror of
https://github.com/Start9Labs/rpc-toolkit.git
synced 2026-03-30 20:24:48 +00:00
fix sync/async mismatch
This commit is contained in:
@@ -5,6 +5,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use clap::{CommandFactory, FromArgMatches};
|
use clap::{CommandFactory, FromArgMatches};
|
||||||
use imbl_value::Value;
|
use imbl_value::Value;
|
||||||
|
use reqwest::header::{ACCEPT, CONTENT_LENGTH, CONTENT_TYPE};
|
||||||
use reqwest::{Client, Method};
|
use reqwest::{Client, Method};
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
@@ -101,25 +102,25 @@ pub async fn call_remote_http(
|
|||||||
let body;
|
let body;
|
||||||
#[cfg(feature = "cbor")]
|
#[cfg(feature = "cbor")]
|
||||||
{
|
{
|
||||||
req = req.header("content-type", "application/cbor");
|
req = req.header(CONTENT_TYPE, "application/cbor");
|
||||||
req = req.header("accept", "application/cbor, application/json");
|
req = req.header(ACCEPT, "application/cbor, application/json");
|
||||||
body = serde_cbor::to_vec(&rpc_req)?;
|
body = serde_cbor::to_vec(&rpc_req)?;
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "cbor"))]
|
#[cfg(not(feature = "cbor"))]
|
||||||
{
|
{
|
||||||
req = req.header("content-type", "application/json");
|
req = req.header(CONTENT_TYPE, "application/json");
|
||||||
req = req.header("accept", "application/json");
|
req = req.header(ACCEPT, "application/json");
|
||||||
body = serde_json::to_vec(&rpc_req)?;
|
body = serde_json::to_vec(&rpc_req)?;
|
||||||
}
|
}
|
||||||
let res = req
|
let res = req
|
||||||
.header("content-length", body.len())
|
.header(CONTENT_LENGTH, body.len())
|
||||||
.body(body)
|
.body(body)
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
match res
|
match res
|
||||||
.headers()
|
.headers()
|
||||||
.get("content-type")
|
.get(CONTENT_TYPE)
|
||||||
.and_then(|v| v.to_str().ok())
|
.and_then(|v| v.to_str().ok())
|
||||||
{
|
{
|
||||||
Some("application/json") => {
|
Some("application/json") => {
|
||||||
|
|||||||
@@ -650,14 +650,16 @@ where
|
|||||||
raw_params,
|
raw_params,
|
||||||
}: HandlerArgsFor<Self::Context, Self>,
|
}: HandlerArgsFor<Self::Context, Self>,
|
||||||
) -> Result<Self::Ok, Self::Err> {
|
) -> Result<Self::Ok, Self::Err> {
|
||||||
self.handler.handle_sync(HandlerArgs {
|
self.handler
|
||||||
context,
|
.handle_async(HandlerArgs {
|
||||||
parent_method,
|
context,
|
||||||
method,
|
parent_method,
|
||||||
params,
|
method,
|
||||||
inherited_params: (self.inherit)(inherited_params.0, inherited_params.1),
|
params,
|
||||||
raw_params,
|
inherited_params: (self.inherit)(inherited_params.0, inherited_params.1),
|
||||||
})
|
raw_params,
|
||||||
|
})
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
fn metadata(
|
fn metadata(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
Reference in New Issue
Block a user