Skip to content

HTTP2: SocketsHttpHandler doesn't downgrade to HTTP/1.1 during Windows authentication #1582

Closed

Description

@davidsh

When SocketsHttpHandler connects to a server using HTTP/2, it is unable to downgrade to HTTP/1.1 when the server requests Windows authentication (Negotiate or NTLM). The net result is that 401 is returned to the client without even trying to reconnect (with HTTP/1.1) and send credentials.

// Repro will be posted later

Activity

  1. geoffkizer commented on Feb 10, 2019

    @geoffkizer
    Contributor

    See also dotnet/corefx#31304

  2. karelz commented on Apr 25, 2019

    @karelz
    Member

    @wfurt can you please chat with @davidsh about design / ideas here?

  3. karelz commented on Apr 25, 2019

    @karelz
    Member

    Given we scoped HTTP/2 to gRPC scenarios, this can wait for post-3.0.

  4. davidsh commented on Apr 25, 2019

    @davidsh
    ContributorAuthor

    Given we scoped HTTP/2 to gRPC scenarios, this can wait for post-3.0.

    Waiting for post-3.0 is ok as long as we don't opt-in by default for HTTP/2.0.

  5. Tratcher commented on May 6, 2019

    @Tratcher
    Member

    I noticed this while doing some auth testing. IE, Chrome, and Edge all have this fallback behavior. Also, the downgrade isn't just for the auth handshake, all subsequent requests are made on the HTTP/1.1 connection so they share the cached auth context.

    WinHttpHandler is a bit different. The first HTTP/2 request challenges, falls back to HTTP/1.1, authenticates, and completes successfully. However, the next request is still made over HTTP/2, the client attempts the fallback again, and then it re-authenticates on the already authenticated connection. That could be a major performance hole to fall into.

  6. transferred this issue fromdotnet/corefxon Jan 9, 2020
  7. added
    untriaged
    on Jan 9, 2020
  8. removed
    untriaged
    on Feb 13, 2020
  9. added this to the Future milestone on Feb 24, 2020
  10. halter73 commented on Dec 5, 2022

    @halter73
    Member

    This came up again. This time from a SignalR client user. See dotnet/aspnetcore#45371. Prior to .NET 7, the SignalR client forced HTTP/1.1 but we started allowing HTTP/2 in .NET 7. We're considering backporting a fix for SignalR to force HTTP/1.1 if the customer sets HttpConnectionOptions.UseDefaultCredentials to true.

    @karelz Even though we have a fix for SignalR, we can't help but think HttpClient should have avoided this for us. Do you think we could do something similar in .NET 8 at the SocketsHttpHandler level when UseDefaultCredentials is set? Of course, the handler could be smarter than SignalR and wait for a challenge before downgrading,

  11. karelz commented on Jan 5, 2023

    @karelz
    Member

    @wfurt @ManickaP @CarnaViire any thoughts on this? (marking for re-triage given new scenario being impacted)

  12. added
    untriaged
    on Jan 5, 2023
  13. wfurt commented on Jan 5, 2023

    @wfurt
    Member

    There are (at least) two distance parts IMHO.

    1. get parity with WinHttp - The existing retry logic will be problematic as this needs new connection (and possibly check for version policy). This can probably be done by refactoring the connection pool logic.
    2. Browsers do have global cache and therefore they can remember state. HttpClientHandler is stateless and each request is processed independently. To fix that, we would need whole new concept in SocketsHttpHandler. That may be useful for other reasons but it would be fundamental change IMHO.

    While we should do something I would keep it in Future for now given complexity and no up votes e.g. no real customer pain. The workaround is somewhat easy -> just set version to 1.1 for problematic sites.

  14. added
    needs-further-triage
    and removed
    untriaged
    on Jan 23, 2023
  15. karelz commented on Jan 24, 2023

    @karelz
    Member

    Agreed with @wfurt. It seems it is still rather rare with a complex solution, so leaving it in Future sounds like the right option now.
    @halter73 let us know if you disagree.

  16. removed
    needs-further-triage
    on Jan 24, 2023
  17. dotMorten commented on Jan 30, 2026

    @dotMorten

    This is a major blocker for us. When a user connects to a service, we don't necessarily know up-front whether it'll be IWA secured. On Windows and Mac we rely on default authentication, so it is completely transparent to the user who just gets auto-signed in. But with http/2 turned on we get a 401 indicating the user's default credential aren't valid and they should provide another set of credentials, but those credentials will also fail. We have no insight into whether the 401 is because of IWA or something else, so our only option is to basically downgrade all webrequests to http/1.1 just in case it hits an IWA service.

    We need some way to detect the request is failing due to IWA so we can downgrade dynamically.
    With PKI authentication we get a specific ProtocolError exception, so we can downgrade ourselves, but with IWA we can't tell the reason for the failure is because of the protocol. The exception thrown is identical to just not providing a credential on http1.1.

    Our QT team hit the same issue with IWA, but they get a callback before connection completes that indicates that IWA credentials are being requested, so if the request fails, they know they just need to downgrade. There doesn't seem to be anything equivalent in .NET.

  18. added
    in-pr
    on Jan 31, 2026
  19. modified the milestones: Future, 11.0.0 on Feb 10, 2026
  20. MihaZupan commented on Apr 18, 2026

    @MihaZupan
    Member

    The change I just merged #123827 works by remembering whether we see a session auth response on HTTP/2, and downgrading all future requests to that endpoint to use HTTP/1.1 (when allowed by version & policy). The initial H2 request that hits this will also be retried as long as it doesn't have a content.

    @dotMorten Would you be able to test how this works in practice in your scenario once the preview with the change comes out (probably p4)?

  21. dotMorten commented on Apr 21, 2026

    @dotMorten

    @MihaZupan Yes I'll take a look then. Thanks!

  22. locked and limited conversation to collaborators on May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-System.Net.Httpbugin-pr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions