undici 8.11.1 → 8.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -700,6 +700,11 @@ function _resume (client, sync) {
700
700
  return
701
701
  }
702
702
 
703
+ if (request.aborted) {
704
+ client[kQueue].splice(client[kPendingIdx], 1)
705
+ continue
706
+ }
707
+
703
708
  if (client[kUrl].protocol === 'https:' && client[kServerName] !== request.servername) {
704
709
  if (client[kRunning] > 0) {
705
710
  return
@@ -101,13 +101,13 @@ function establishWebSocketConnection (url, protocols, client, handler, options)
101
101
  // The presence of a session property on the socket indicates HTTP2
102
102
  // HTTP1
103
103
  if (response.socket?.session == null) {
104
- failWebsocketConnection(handler, 1002, 'Received network error or non-101 status code.', response.error)
104
+ failHandshake(handler, response, 1002, 'Received network error or non-101 status code.', response.error)
105
105
  return
106
106
  }
107
107
 
108
108
  // HTTP2
109
109
  if (response.status !== 200) {
110
- failWebsocketConnection(handler, 1002, 'Received network error or non-200 status code.', response.error)
110
+ failHandshake(handler, response, 1002, 'Received network error or non-200 status code.', response.error)
111
111
  return
112
112
  }
113
113
  }
@@ -122,7 +122,7 @@ function establishWebSocketConnection (url, protocols, client, handler, options)
122
122
  // header list results in null, failure, or the empty byte
123
123
  // sequence, then fail the WebSocket connection.
124
124
  if (protocols.length !== 0 && !response.headersList.get('Sec-WebSocket-Protocol')) {
125
- failWebsocketConnection(handler, 1002, 'Server did not respond with sent protocols.')
125
+ failHandshake(handler, response, 1002, 'Server did not respond with sent protocols.')
126
126
  return
127
127
  }
128
128
 
@@ -138,7 +138,7 @@ function establishWebSocketConnection (url, protocols, client, handler, options)
138
138
  // _Fail the WebSocket Connection_.
139
139
  // For H2, no upgrade header is expected.
140
140
  if (response.socket.session == null && response.headersList.get('Upgrade')?.toLowerCase() !== 'websocket') {
141
- failWebsocketConnection(handler, 1002, 'Server did not set Upgrade header to "websocket".')
141
+ failHandshake(handler, response, 1002, 'Server did not set Upgrade header to "websocket".')
142
142
  return
143
143
  }
144
144
 
@@ -148,7 +148,7 @@ function establishWebSocketConnection (url, protocols, client, handler, options)
148
148
  // MUST _Fail the WebSocket Connection_.
149
149
  // For H2, no connection header is expected.
150
150
  if (response.socket.session == null && response.headersList.get('Connection')?.toLowerCase() !== 'upgrade') {
151
- failWebsocketConnection(handler, 1002, 'Server did not set Connection header to "upgrade".')
151
+ failHandshake(handler, response, 1002, 'Server did not set Connection header to "upgrade".')
152
152
  return
153
153
  }
154
154
 
@@ -165,7 +165,7 @@ function establishWebSocketConnection (url, protocols, client, handler, options)
165
165
  const secWSAccept = response.headersList.get('Sec-WebSocket-Accept')
166
166
  const digest = crypto.hash('sha1', keyValue + uid, 'base64')
167
167
  if (secWSAccept !== digest) {
168
- failWebsocketConnection(handler, 1002, 'Incorrect hash received in Sec-WebSocket-Accept header.')
168
+ failHandshake(handler, response, 1002, 'Incorrect hash received in Sec-WebSocket-Accept header.')
169
169
  return
170
170
  }
171
171
  }
@@ -184,7 +184,7 @@ function establishWebSocketConnection (url, protocols, client, handler, options)
184
184
  extensions = parseExtensions(secExtension)
185
185
 
186
186
  if (!extensions.has('permessage-deflate')) {
187
- failWebsocketConnection(handler, 1002, 'Sec-WebSocket-Extensions header does not match.')
187
+ failHandshake(handler, response, 1002, 'Sec-WebSocket-Extensions header does not match.')
188
188
  return
189
189
  }
190
190
  }
@@ -205,7 +205,7 @@ function establishWebSocketConnection (url, protocols, client, handler, options)
205
205
  // the selected subprotocol values in its response for the connection to
206
206
  // be established.
207
207
  if (requestProtocols === null || !requestProtocols.includes(secProtocol)) {
208
- failWebsocketConnection(handler, 1002, 'Protocol was not set in the opening handshake.')
208
+ failHandshake(handler, response, 1002, 'Protocol was not set in the opening handshake.')
209
209
  return
210
210
  }
211
211
  }
@@ -307,6 +307,16 @@ function closeWebSocketConnection (object, code, reason, validate = false) {
307
307
  }
308
308
  }
309
309
 
310
+ function failHandshake (handler, response, code, reason, cause) {
311
+ // The H2 upgrade request has already completed and handed off its stream.
312
+ // Aborting the request cannot close that stream after handshake validation fails.
313
+ if (response.socket?.session != null && !response.socket.destroyed) {
314
+ response.socket.destroy()
315
+ }
316
+
317
+ failWebsocketConnection(handler, code, reason, cause)
318
+ }
319
+
310
320
  /**
311
321
  * @param {import('./websocket').Handler} handler
312
322
  * @param {number} code
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "undici",
3
- "version": "8.11.1",
3
+ "version": "8.11.2",
4
4
  "description": "An HTTP/1.1 client, written from scratch for Node.js",
5
5
  "homepage": "https://undici.nodejs.org",
6
6
  "bugs": {