Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpWebClient always send Cache-Control and Pragma headers when proxy used #110164

Closed
zxcvqwerasdf opened this issue Nov 25, 2024 · 3 comments
Closed

Comments

@zxcvqwerasdf
Copy link

I tried different ways, but when you use HttpClient with Proxy you will get Cache-Control: no-cache and Pragma: no-cache in request headers.
It's possible to prevent it? I don't need these headers when using proxy.

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Nov 25, 2024
@MihaZupan
Copy link
Member

HttpClient on its own will not inject these headers. Could it be that whatever proxy server you're using is doing so for you?

@MihaZupan MihaZupan added the needs-author-action An issue or pull request that requires more info or actions from the author. label Nov 25, 2024
@zxcvqwerasdf
Copy link
Author

zxcvqwerasdf commented Nov 25, 2024

HttpClient on its own will not inject these headers. Could it be that whatever proxy server you're using is doing so for you?

 var socketHandler = new SocketsHttpHandler
 {
     AllowAutoRedirect = false,
     UseCookies = false,
     UseProxy = true,
     Proxy = new WebProxy($"http://{proxy.host}:{proxy.port_http}")
 };

 var httpClient = new HttpClient(socketHandler, true);
 HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, URL);
 request.Version = new Version(1, 1);
 var response = await httpClient.SendAsync(request);

If you will use local proxy, you will find these headers
Image
in request

but if you change

UseProxy = false

there will be no these headers (you can check it by writing some server that check request header/print it in response headers)

@dotnet-policy-service dotnet-policy-service bot removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Nov 25, 2024
@zxcvqwerasdf
Copy link
Author

Sorry, checked it in 2 another local proxies and there is no these headers

@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants