From 830780a9e799494082f13e6aac9d8a71458e9b58 Mon Sep 17 00:00:00 2001 From: Kevin Abramczyk Date: Sun, 22 Nov 2026 14:05:08 -0500 Subject: [PATCH] fix(rpc): read chunked responses from the bitcoind RPC server `bitcoincore_rpc::Client::new` always uses jsonrpc's `simple_http` transport, which rejects responses sent with `Transfer-Encoding: chunked` ("The server replied with a chunked response which is not supported"). Servers that stream JSON-RPC responses chunked, such as libbitcoin-server, cannot be used with `--client-type rpc`. Build the RPC client over jsonrpc's `minreq_http` transport instead, which reads chunked and content-length responses. bitcoincore-rpc 0.19 already enables the `minreq_http` feature of jsonrpc, so no dependency changes. minreq requires a URL scheme while simple_http defaulted to http, so `http://` is prepended when the URL has none (e.g. `127.0.0.1:18443`). --- CHANGELOG.md | 1 + src/client.rs | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb4e2aaa..08e50a7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ page. See [DEVELOPMENT_CYCLE.md](DEVELOPMENT_CYCLE.md) for more details. - Fixed `key generate` silently producing a 24-word mnemonic for any `--entropy` value other than 12; values other than 12 and 24 are now rejected - Gated `full_scan`'s `--scan-stop-gap` to the Electrum and Esplora backends that use it; RPC and CBF wallets now reject the flag instead of silently ignoring it, while a `STOP_GAP` environment variable keeps working for supported backends and no longer breaks unsupported ones - Changed `payjoin history` to return JSON instead of a rendered table +- Fixed the `rpc` backend failing against servers that send chunked responses ("The server replied with a chunked response which is not supported"); the RPC client now uses jsonrpc's `minreq_http` transport ## [4.0.0] diff --git a/src/client.rs b/src/client.rs index 8937178f..6fad7c20 100644 --- a/src/client.rs +++ b/src/client.rs @@ -248,6 +248,38 @@ fn esplora_proxy_url(proxy_opts: &ProxyOpts) -> Option { }) } +/// Create a bitcoind RPC client over the minreq HTTP transport, which reads +/// chunked responses. The default simple_http transport rejects them. +#[cfg(feature = "rpc")] +fn rpc_client( + url: &str, + auth: bdk_bitcoind_rpc::bitcoincore_rpc::Auth, +) -> Result { + use bdk_bitcoind_rpc::bitcoincore_rpc::{self, jsonrpc}; + + let rpc_error = + |e: jsonrpc::Error| Error::BitcoinCoreRpcError(bitcoincore_rpc::Error::JsonRpc(e)); + let (user, pass) = auth.get_user_pass().map_err(Error::BitcoinCoreRpcError)?; + + // simple_http accepts a url without a scheme, minreq requires one. + let url = if url.contains("://") { + url.to_string() + } else { + format!("http://{url}") + }; + + let mut builder = jsonrpc::minreq_http::Builder::new() + .url(&url) + .map_err(|e| rpc_error(e.into()))?; + if let Some(user) = user { + builder = builder.basic_auth(user, pass); + } + + Ok(bitcoincore_rpc::Client::from_jsonrpc( + jsonrpc::Client::with_transport(builder.build()), + )) +} + #[cfg(any( feature = "electrum", feature = "esplora", @@ -300,8 +332,7 @@ pub(crate) fn new_blockchain_client( wallet_opts.basic_auth.1.clone(), ), }; - let client = bdk_bitcoind_rpc::bitcoincore_rpc::Client::new(url, auth) - .map_err(Error::BitcoinCoreRpcError)?; + let client = rpc_client(url, auth)?; BlockchainClient::RpcClient { client: Box::new(client), }