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

Adding accept header to callsites within SignalR #55271

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

MattyLeslie
Copy link
Contributor

@MattyLeslie MattyLeslie commented Apr 22, 2024

Adding accept header to callsites within SignalR

Summary of the changes
As mentioned in #47398, many of the HttpClient call sites within the SignalR library were missing their appropriate accept headers. This change aims to address that issue.

Description
Changes made include:

  1. Adding accept header to Negotiate() within HttpConnection to ensure header is present for negotiation requests.
  2. Adding accept header to SendMessage() within SendUtils for the send requests.
  3. Adding accept header to Poll() within LongPollingTransport for the get request.
  4. Test to ensure first request and subsequent polling requests for LongPollingTransport have the correct accept header
  5. Test to ensure the request for ServerSentEventsTransport has the correct accept header
  6. Test to ensure the negotiate in HttpConnection has the correct accept header.

Fixes #47398 by ensuring the negotiation requests and other HttpClient call sites of SignalR are made with the relevant accept header.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-signalr Includes: SignalR clients and servers label Apr 22, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Apr 22, 2024
@BrennanConroy
Copy link
Member

Are you actually changing anything, or just kicking the build? If it's kicking the build please stop.
Also, could you please look into adding tests, see

Assert.Equal("text/event-stream", context.Response.ContentType);
as an example.

@BrennanConroy
Copy link
Member

Looks like you're missing negotiate? Otherwise I think that covers all the spots.

@dotnet-policy-service dotnet-policy-service bot added this to the 9.0-preview5 milestone Apr 29, 2024
@BrennanConroy
Copy link
Member

I'm sorry to see this closed, anything I can help with? It looked really close to finished.

@MattyLeslie MattyLeslie reopened this May 2, 2024
…t testing. Adding an optional HttpMessageHandler parameter for CreateHttpClient.
@MattyLeslie
Copy link
Contributor Author

Hello @BrennanConroy,

I've reopened the PR and pushed some new commits.

I'm encountering a couple of challenges that I'm currently addressing:

  1. For the ServerSentEventsTransport.cs call site, the test hangs if the accept header is missing from the request in the StartAsync() method.
  2. The test I created for the NegotiateAsync() method in HttpConnection.cs isn't passing. It seems that not all dependencies are being adequately mocked.

To better test the NegotiateAsync() method, I modified the unit testing constructor to accept a nullable HttpMessageHandler. This change allows me to mock HttpMessageHandler in the CreateHttpClient() method, enabling me to verify the outgoing requests made by the HttpClient during NegotiateAsync(). I hope this change is appropriate.

I welcome any constructive feedback on the testing approach I've implemented for the various call sites. I'm actively working to resolve the issues mentioned above.

@BrennanConroy
Copy link
Member

To better test the NegotiateAsync() method, I modified the unit testing constructor to accept a nullable HttpMessageHandler. This change allows me to mock HttpMessageHandler in the CreateHttpClient() method, enabling me to verify the outgoing requests made by the HttpClient during NegotiateAsync(). I hope this change is appropriate.

Why not use HttpConnectionOptions.HttpMessageHandlerFactory?

HttpMessageHandlerFactory = handler => new GetNegotiateHttpHandler(handler, stream)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-signalr Includes: SignalR clients and servers community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SignalR: Missing Accept-Header
3 participants