Skip to content

Failure due to context-sensitive checking of HTTP header Content-Length #193

@optout21

Description

@optout21

Describe the bug
Electrs fails if an RPC response contains the "Content-Length" header in lowercase.

Electrs version
0.4.1 , also current main

To Reproduce
I'm developing a bitcoin RPC proxy, https://github.com/optout21/localpool
When it is configured between a bitcoin core node (v28.1) and electrs (v0.4.1), and forwards RCP calls unmodified, electrs fails to start properly. If it is connected directly, it is OK. The only difference in the response from bitcoin core and from the proxy is the capitalization of "Content-Length" and "Content-Type".

Expected behavior
HTTP headers should be case-insensitive, as per the RFC standards.

Additional context
I can see case-sensitive check for the header here:
https://github.com/Blockstream/electrs/blob/new-index/src/daemon.rs#L279

        let contents_length: &str = headers
            .get("Content-Length")
            .chain_err(|| format!("Content-Length is missing: {:?}", headers))?;

Note that HTTP headers are supposed to be case-insensitve, and particularly, Rust toolset using http crate produce LOWERCASE headers, see:
https://docs.rs/http/1.0.0/http/header/struct.HeaderName.html#method.as_str

As for the failure, I don't see error or differences in the logs (with -vvv), but after start, electr seems to get stuck, and does not respond to any connections. Last log lines are:

Mar 12 12:30:01 vcpu-1gb-amd-ny electrs[315727]: Config { log: StdErrLog { verbosity: Debug, quiet: false, show_level: true, timestamp: Off, modules: [], writer: "stderr", color_choice: Never, show_module_names: false }, network_type: Signet, db_path: "/var/lib/electrs/signet", daemon_dir: "/var/lib/bitcoind/signet", blocks_dir: "/var/lib/bitcoind/signet/blocks", daemon_rpc_addr: 127.0.0.1:38432, daemon_parallelism: 4, cookie: None, electrum_rpc_addr: 127.0.0.1:60601, http_addr: 127.0.0.1:3003, http_socket_file: None, monitoring_addr: 127.0.0.1:54224, jsonrpc_import: false, light_mode: true, address_search: false, index_unspendables: false, cors: None, precache_scripts: None, utxos_limit: 500, electrum_txs_limit: 500, electrum_banner: "Welcome to electrs-esplora 0.4.1", electrum_rpc_logging: None, zmq_addr: None, initial_sync_compaction: false }
Mar 12 12:30:01 1vcpu-1gb-amd-ny electrs[315727]: DEBUG Server listening on 127.0.0.1:54224
Mar 12 12:30:01 1vcpu-1gb-amd-ny electrs[315727]: DEBUG Running accept thread

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions