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

Websocket handshake refactoring. #31506

Merged
merged 9 commits into from
Apr 29, 2021
Merged

Websocket handshake refactoring. #31506

merged 9 commits into from
Apr 29, 2021

Conversation

ShreyasJejurkar
Copy link
Contributor

@ShreyasJejurkar ShreyasJejurkar commented Apr 3, 2021

Addresses #31373

I have moved CheckSupportedWebSocketRequest method from HandShakeHelpers to WebSocketMiddleware.
I am not getting what needs to be done for NeededHeaders do we want to remove those directly?

cc @Tratcher

@ghost ghost added area-runtime community-contribution Indicates that the PR has been added by a community member labels Apr 3, 2021
@BrennanConroy
Copy link
Member

I think the main thing is that the temporary interestingHeaders allocation isn't needed if we merged the two methods.

@umitkavala
Copy link

Yeah. Instead of allocation you'd do query on request headers directly.
You may do something like this I guess.

public bool IsWebSocketRequest
           {
               get
               {
                   if (_isWebSocketRequest == null)
                   {
                       if (!_upgradeFeature.IsUpgradableRequest)
                       {
                           _isWebSocketRequest = false;
                       }
                       else
                       {
                           _isWebSocketRequest = CheckSupportedWebSocketRequest(_context.Request.Method, _context.Request.Headers);
                       }
                   }
                   return _isWebSocketRequest.Value;
               }
           }

           public static bool CheckSupportedWebSocketRequest(string method, IHeaderDictionary requestHeaders)
           {
               bool validUpgrade = false, validConnection = false, validKey = false, validVersion = false;

               if (!string.Equals("GET", method, StringComparison.OrdinalIgnoreCase))
               {
                   return false;
               }

               foreach (var pair in requestHeaders)
               {
                   if (string.Equals(HeaderNames.Connection, pair.Key, StringComparison.OrdinalIgnoreCase))
                   {
                       check requestHeaders.GetCommaSeparatedValues(HeaderNames.Connection) instead below and other ifs
                      // if (string.Equals(HeaderNames.Upgrade, pair.Value, StringComparison.OrdinalIgnoreCase))
                       {
                           validConnection = true;
                       }
                   }
.......

@davidfowl
Copy link
Member

Assigned to @Tratcher since he suggested the change 😄

@ShreyasJejurkar
Copy link
Contributor Author

Hi @BrennanConroy, I have removed an extra parameter to that method, and moved interestingHeaders to another method. Yeah, I haven't yet removed intrestingHeaders.
But I am not understanding before iterating request headers directly, we want to iterate only specific headers correct? So before foreach we need to anyhow filter them!

Sorry, if I am missing any important point!

@ShreyasJejurkar
Copy link
Contributor Author

Hi @umitkavala , Thanks for the reply. But GetCommaSeparatedValues don't return boolean to check condition, it returns array of string!

@BrennanConroy
Copy link
Member

Oh good, tests failed, means we have good coverage 😃

@Tratcher Tratcher added the pr: pending author input For automation. Specifically separate from Needs: Author Feedback label Apr 21, 2021
2. Moved intrestingheaders directly to other method instead of paramter (WIP)
1. And refactored a little bit.
@BrennanConroy BrennanConroy removed the pr: pending author input For automation. Specifically separate from Needs: Author Feedback label Apr 28, 2021
@BrennanConroy
Copy link
Member

Updated

@@ -146,29 +146,22 @@ public async Task SendLongData_Success()

var serverBuffer = new byte[orriginalData.Length];
var result = await webSocket.ReceiveAsync(new ArraySegment<byte>(serverBuffer), CancellationToken.None);
int intermediateCount = result.Count;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test has been broken for 5 years...

@BrennanConroy BrennanConroy merged commit db8a649 into dotnet:main Apr 29, 2021
@ghost ghost added this to the 6.0-preview5 milestone Apr 29, 2021
@BrennanConroy
Copy link
Member

Thanks @MCCshreyas ! Hope your computer issues are resolved soon 😃

@ShreyasJejurkar
Copy link
Contributor Author

Not yet @BrennanConroy, I ordered a SSD, not sure when it will get delivered now! 😅😅

But thanks for taking care of this PR. 😊
Much appreciated!

@ghost
Copy link

ghost commented Apr 30, 2021

Hi @MCCshreyas. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context.

@ShreyasJejurkar ShreyasJejurkar deleted the websocket-refactoring branch April 30, 2021 08:12
@amcasey amcasey added area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares and removed area-runtime labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares 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.

6 participants