Skip to content

Change WebSocket handshake implementation to align with the .NET approach#5740

Open
imcarolwang wants to merge 4 commits into
dotnet:mainfrom
imcarolwang:issue5729
Open

Change WebSocket handshake implementation to align with the .NET approach#5740
imcarolwang wants to merge 4 commits into
dotnet:mainfrom
imcarolwang:issue5729

Conversation

@imcarolwang

Copy link
Copy Markdown
Contributor

For issue #5729 .

@imcarolwang

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@imcarolwang

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@imcarolwang

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@imcarolwang

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@imcarolwang
imcarolwang marked this pull request as ready for review February 27, 2025 02:57
imcarolwang and others added 4 commits June 15, 2026 09:37
Restore behavior that was lost when ClientWebSocket.ConnectAsync was
replaced with the manual SocketsHttpHandler-based handshake:

- Initialize _webRequestTokenProvider / _webRequestProxyTokenProvider via
  CreateAndOpenTokenProvidersAsync at the top of SetupInvoker; otherwise
  GetCredentialAsync and the proxy factory receive null providers,
  breaking Basic/Digest/Negotiate/NTLM client auth and authenticated
  proxy.
- Set the Host request header via MapIdentity / GetIdentityHostHeader so
  EndpointIdentity-based Kerberos SPN/DNS/UPN scenarios continue to
  authenticate against the identity host instead of the URI host.
- Pass a cancellation token derived from TimeoutHelper into SendAsync so
  OpenAsync(timeout) honors the user-supplied timeout instead of hanging
  on DNS/TCP/TLS/server stalls.
- Stop setting handler.UseProxy = false in the no-explicit-proxy branch;
  leaving the SocketsHttpHandler default preserves system / default web
  proxy behavior, matching the prior ClientWebSocket implementation.
- Remove the while(true) + HttpRequestError.ExtendedConnectNotSupported
  catch: the request is hard-coded to HTTP/1.1 with RequestVersionExact
  per Matt's guidance, so the catch was dead code with an infinite-loop
  hazard if it ever fired.
- After parsing Sec-WebSocket-Protocol, fail when the client requested a
  subprotocol but the server returned none, preserving the prior strict
  WCF behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds an outerloop scenario test that configures NetHttpsBinding with
WebSocketTransportUsage.Always and a custom
ServiceCertificate.SslCertificateAuthentication validator, but does NOT
require a client certificate. This is the exact scenario from issue
dotnet#5729: prior to the fix, the custom RemoteCertificateValidationCallback
was only wired when RequireClientCertificate was true, so the validator
was silently bypassed.

The test asserts that the custom validator's Validate method was
actually invoked during the WebSocket handshake, which would have failed
before the fix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant