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

X-NuGet-Warning doesn't work when using proxy due to missing ServerWarningLogHandler #5004

Closed
zarenner opened this issue Apr 10, 2017 · 5 comments · Fixed by NuGet/NuGet.Client#5021

Comments

@zarenner
Copy link

zarenner commented Apr 10, 2017

The code that sets up ProxyAuthenticationHandler is missing ServerWarningLogHandler: https://github.com/NuGet/NuGet.Client/blob/7645448a1fbeff4bc17b9c74be115aa92c5b9b4a/src/NuGet.Core/NuGet.Protocol/HttpSource/HttpHandlerResourceV3Provider.cs#L55

As such, X-NuGet-Warning doesn't work when using a proxy (even fiddler).

@rohit21agrawal
Copy link
Contributor

Thanks for the bug report @zarenner . We will investigate this as soon as we can.

@jotaylo
Copy link

jotaylo commented Jul 13, 2018

Well over a year later, this is still an issue.

@0xced
Copy link

0xced commented Jan 18, 2023

And almost 6 years later, this is still an issue. I've been hit by this because a private feed I'm using emits the X-NuGet-Warning header to inform me about an expired subscription. But I've never seen this warning because I'm using a proxy and I lost half a day debugging the NuGet restore task trying to figure out why the NuGet package would not restore properly. 🙄 (The NuGet feed redirects to the latest package version available for my subscription.)

@0xced
Copy link

0xced commented Jan 20, 2023

The proxy issue could be easily solved by setting the inner handler, just like it's done for the StsAuthenticationHandler and HttpSourceAuthenticationHandler, i.e.:

var innerHandler = messageHandler;
messageHandler = new ProxyAuthenticationHandler(clientHandler, HttpHandlerResourceV3.CredentialService?.Value, ProxyCache.Instance)
{
    InnerHandler = innerHandler
};

instead of the current

messageHandler = new ProxyAuthenticationHandler(clientHandler, HttpHandlerResourceV3.CredentialService?.Value, ProxyCache.Instance);

For my particular private feed there was another issue that is not as easily solved: the X-NuGet-Warning header is issued during redirection (HTTP status 302) which is invisible since the HttpClientHandler is configured to automatically follow redirects.

curl --user my-user:my-password -i https://nuget.example.com/api/v3/packages/download/the.package/3.0.0/the.package.3.0.0.nupkg
HTTP/1.1 302 Found
Server: nginx/1.18.0 (Ubuntu)
Date: Thu, 20 Jan 2023 08:48:36 GMT
Content-Length: 0
Connection: keep-alive
Location: /api/v3/packages/download/the.package/2.5.0/the.package.2.5.0.nupkg
X-NuGet-Warning: Package 'The.Package 3.0.0' cannot be downloaded because required subscription has expired. Redirecting to the latest available version: 2.5.0

@zivkan
Copy link
Member

zivkan commented May 5, 2023

Thank you @0xced for fixing the bug!

The fix will be available in NuGet 6.7, VS 17.7, .NET SDK 7.0.400

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants