Discrepancies between self-prepared and session-prepared request headers
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 54.3k
- Forks
- 10.4k
- Avg merge
- 16h 43m
- Merged PRs (30d)
- 3
Description
If we prepare a request normally (the prepare() method), it does not include any additional headers by default, even if the resulting prepared request is sent via a session.
However, if the request is prepared via the session (the prepare_request(Request) method), then it will include a few headers by default: Accept, Accept-Encoding, User-Agent, and Connection.
There are some (arguably buggy) HTTP servers that apparently will reject any request that includes the Accept or Accept-Encoding header with 406 Not Acceptable.
This situation led to major confusion when trying to fix our usage of this library to send all the requests through a single session in order to leverage cookie handling.
This default header logic does not appear to be documented anywhere. I also think it is very confusing that a self-prepared request and a session-prepared request would have different headers. Unfortunately, I assume this cannot be changed easily for fear of breaking backwards compatibility.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading Request.prepare() and Session.prepare_request(Request), the two entry points named in the report, and compare how their default headers are assembled. Review the existing comments for the compatibility concerns and determine whether the intended outcome is documentation, aligned behavior, or both; done should include tests covering the differing headers and the chosen behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100