[API] Add per request headers override to HttpClient convenience methods
## Motivation Custom per request http headers importance are on the rise due to their role in authentication and authentication in newer api security models. The way to send custom per request headers with `HttpClient` is via `SendAsync` and adding them to the `HttpRequestMessage`. However that isn't very discoverable and is a big jump from using the convenience methods `GetAsync`, `PostAsync`, etc This can lead people to changing the `DefaultRequestHeaders` on the `HttpClient` instead: [SO](https://stackoverflow.com/a/35910012/1109918), [SO](https://stackoverflow.com/q/42156953/1109918), [SO](https://stackoverflow.com/q/10679214/1109918), etc Which is very dangerous if the `HttpClient` is used as a static; which is [also an official suggested practice](https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client) > **HttpClient** is intended to be instantiated once and re-used throughout the life of an application. Especially in server applications, creating a new **HttpClient** instance for every request will exhaust the number of sockets available under heavy loads. This will result in **SocketException** errors. And in popular blogs ["You're using HttpClient wrong and it is destabilizing your software"](https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/) > This is dramatic. If you have any kind of load at all you need to remember these two things: > > 1. Make your HttpClient static. > 2. Do not dispose of or wr
Posted by benaadams on Aug 25, 2017, 4:14 AM
Tags
Related issues
- 2026 - Microsoft Office 365
- [Ubuntu] `ubuntu-latest` label will use Ubuntu 26.04 in November 2026
- Gamut mapping
- [Codex Desktop] Editing and resending a queued message triggers "App-server queued follow-up no longer exists"
- [Windows] ChatGPT 26.820.60940 fails with "invalid transport in mcp_servers.codex_app"; Beta 26.727.40816 works
- [BUG]: infinite loading of videos
Raise real-world problems, find people facing the same issue, and discuss solutions.4,500 issues0 comments
github (SaaS)
2026 - Microsoft Office 365
[Ubuntu] `ubuntu-latest` label will use Ubuntu 26.04 in November 2026
Gamut mapping
[Codex Desktop] Editing and resending a queued message triggers "App-server queued follow-up no longer exists"
[Windows] ChatGPT 26.820.60940 fails with "invalid transport in mcp_servers.codex_app"; Beta 26.727.40816 works
[BUG]: infinite loading of videos
Restore GPT-5.6 Sol’s 372k Codex context window, or provide an opt-in setting
Codex Desktop for macOS repeatedly triggers `syspolicyd` / `trustd` CPU and memory runaway
[API] Add per request headers override to HttpClient convenience methods
## Motivation Custom per request http headers importance are on the rise due to their role in authentication and authentication in newer api security models. The way to send custom per request headers with `HttpClient` is via `SendAsync` and adding them to the `HttpRequestMessage`. However that isn't very discoverable and is a big jump from using the convenience methods `GetAsync`, `PostAsync`, etc This can lead people to changing the `DefaultRequestHeaders` on the `HttpClient` instead: [SO](https://stackoverflow.com/a/35910012/1109918), [SO](https://stackoverflow.com/q/42156953/1109918), [SO](https://stackoverflow.com/q/10679214/1109918), etc Which is very dangerous if the `HttpClient` is used as a static; which is [also an official suggested practice](https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client) > **HttpClient** is intended to be instantiated once and re-used throughout the life of an application. Especially in server applications, creating a new **HttpClient** instance for every request will exhaust the number of sockets available under heavy loads. This will result in **SocketException** errors. And in popular blogs ["You're using HttpClient wrong and it is destabilizing your software"](https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/) > This is dramatic. If you have any kind of load at all you need to remember these two things: > > 1. Make your HttpClient static. > 2. Do not dispose of or wr
Comments (0)
No comments yet. Start the discussion.