Skip to content

Conversation

@itsibitzi
Copy link

@itsibitzi itsibitzi commented Oct 13, 2025

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 itsibitzi changed the title Add default headers as request is built Add default headers as request is built in Client::request Oct 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant