reqwest icon indicating copy to clipboard operation
reqwest copied to clipboard

Add default headers as request is built in `Client::request`

Open itsibitzi opened this issue 2 months ago • 0 comments

Motivation

As a few people have pointed out in issues it's a bit surprising that the default headers from a Client are not added to a Request built by Client::request until the request is sent. I personally would consider this a bug, not sure about everyone else though! :)

My particular use case is using reqwest both for sending HTTP requests but also in-memory only during testing (without actually executing the request).

Implementation

The implementation is based on piecing together a few comments throughout various issues.

I added the headers in during Client::request. If the duplication in the async/blocking client is annoying then I could add Request::new_with_headers or something?

I've left the existing merge from execute_request for the code path where someone doesn't use a builder and just passes in a Request object directly to Client::execute.

I've added a test to tests/client.rs which asserts this new behaviour. The header values are copied from the docs.

itsibitzi avatar Oct 13 '25 14:10 itsibitzi