Skip to content

Refactor inefficient WebSocket handshake #31373

Closed
@benaadams

Description

@benaadams

This HandshakeHelpers class is a relic of an outdated design. Can you try simplifying this code by merging this method into the UpgradeHandshake class?

You could remove these allocations and query the header collection directly:

var headers = new List<KeyValuePair<string, string>>();
foreach (string headerName in HandshakeHelpers.NeededHeaders)
{
foreach (var value in _context.Request.Headers.GetCommaSeparatedValues(headerName))
{
headers.Add(new KeyValuePair<string, string>(headerName, value));
}
}

NeededHeaders can also be removed.

#31311 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Perfarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsgood first issueGood for newcomers.help wantedUp for grabs. We would accept a PR to help resolve this issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions