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

perf(websocket): avoid toLowerCase call #2550

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/websocket/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ function establishWebSocketConnection (url, protocols, ws, onEstablish, options)

// 6. Append (`Sec-WebSocket-Key`, keyValue) to request’s
// header list.
request.headersList.append('sec-websocket-key', keyValue)
request.headersList.append('sec-websocket-key', keyValue, true)

// 7. Append (`Sec-WebSocket-Version`, `13`) to request’s
// header list.
request.headersList.append('sec-websocket-version', '13')
request.headersList.append('sec-websocket-version', '13', true)

// 8. For each protocol in protocols, combine
// (`Sec-WebSocket-Protocol`, protocol) in request’s header
// list.
for (const protocol of protocols) {
request.headersList.append('sec-websocket-protocol', protocol)
request.headersList.append('sec-websocket-protocol', protocol, true)
}

// 9. Let permessageDeflate be a user-agent defined
Expand Down Expand Up @@ -133,7 +133,7 @@ function establishWebSocketConnection (url, protocols, ws, onEstablish, options)
// header field contains a value that is not an ASCII case-
// insensitive match for the value "websocket", the client MUST
// _Fail the WebSocket Connection_.
if (response.headersList.get('Upgrade')?.toLowerCase() !== 'websocket') {
if (response.headersList.get('upgrade', true)?.toLowerCase() !== 'websocket') {
failWebsocketConnection(ws, 'Server did not set Upgrade header to "websocket".')
return
}
Expand All @@ -142,7 +142,7 @@ function establishWebSocketConnection (url, protocols, ws, onEstablish, options)
// |Connection| header field doesn't contain a token that is an
// ASCII case-insensitive match for the value "Upgrade", the client
// MUST _Fail the WebSocket Connection_.
if (response.headersList.get('Connection')?.toLowerCase() !== 'upgrade') {
if (response.headersList.get('connection', true)?.toLowerCase() !== 'upgrade') {
failWebsocketConnection(ws, 'Server did not set Connection header to "upgrade".')
return
}
Expand All @@ -154,7 +154,7 @@ function establishWebSocketConnection (url, protocols, ws, onEstablish, options)
// E914-47DA-95CA-C5AB0DC85B11" but ignoring any leading and
// trailing whitespace, the client MUST _Fail the WebSocket
// Connection_.
const secWSAccept = response.headersList.get('Sec-WebSocket-Accept')
const secWSAccept = response.headersList.get('sec-websocket-accept', true)
const digest = crypto.createHash('sha1').update(keyValue + uid).digest('base64')
if (secWSAccept !== digest) {
failWebsocketConnection(ws, 'Incorrect hash received in Sec-WebSocket-Accept header.')
Expand All @@ -168,7 +168,7 @@ function establishWebSocketConnection (url, protocols, ws, onEstablish, options)
// MUST _Fail the WebSocket Connection_. (The parsing of this
// header field to determine which extensions are requested is
// discussed in Section 9.1.)
const secExtension = response.headersList.get('Sec-WebSocket-Extensions')
const secExtension = response.headersList.get('sec-websocket-extensions', true)

if (secExtension !== null && secExtension !== permessageDeflate) {
failWebsocketConnection(ws, 'Received different permessage-deflate than the one set.')
Expand All @@ -180,9 +180,9 @@ function establishWebSocketConnection (url, protocols, ws, onEstablish, options)
// not present in the client's handshake (the server has indicated a
// subprotocol not requested by the client), the client MUST _Fail
// the WebSocket Connection_.
const secProtocol = response.headersList.get('Sec-WebSocket-Protocol')
const secProtocol = response.headersList.get('sec-websocket-protocol', true)

if (secProtocol !== null && secProtocol !== request.headersList.get('Sec-WebSocket-Protocol')) {
if (secProtocol !== null && secProtocol !== request.headersList.get('sec-websocket-protocol', true)) {
failWebsocketConnection(ws, 'Protocol was not set in the opening handshake.')
return
}
Expand Down
4 changes: 2 additions & 2 deletions lib/websocket/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ class WebSocket extends EventTarget {
// 2. Change the extensions attribute’s value to the extensions in use, if
// it is not the null value.
// https://datatracker.ietf.org/doc/html/rfc6455#section-9.1
const extensions = response.headersList.get('sec-websocket-extensions')
const extensions = response.headersList.get('sec-websocket-extensions', true)

if (extensions !== null) {
this.#extensions = extensions
Expand All @@ -527,7 +527,7 @@ class WebSocket extends EventTarget {
// 3. Change the protocol attribute’s value to the subprotocol in use, if
// it is not the null value.
// https://datatracker.ietf.org/doc/html/rfc6455#section-1.9
const protocol = response.headersList.get('sec-websocket-protocol')
const protocol = response.headersList.get('sec-websocket-protocol', true)

if (protocol !== null) {
this.#protocol = protocol
Expand Down
Loading