undici 5.15.0 → 5.15.1

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.
package/lib/client.js CHANGED
@@ -441,6 +441,7 @@ class Parser {
441
441
 
442
442
  this.keepAlive = ''
443
443
  this.contentLength = ''
444
+ this.connection = ''
444
445
  this.maxResponseSize = client[kMaxResponseSize]
445
446
  }
446
447
 
@@ -616,6 +617,8 @@ class Parser {
616
617
  const key = this.headers[len - 2]
617
618
  if (key.length === 10 && key.toString().toLowerCase() === 'keep-alive') {
618
619
  this.keepAlive += buf.toString()
620
+ } else if (key.length === 10 && key.toString().toLowerCase() === 'connection') {
621
+ this.connection += buf.toString()
619
622
  } else if (key.length === 14 && key.toString().toLowerCase() === 'content-length') {
620
623
  this.contentLength += buf.toString()
621
624
  }
@@ -709,7 +712,11 @@ class Parser {
709
712
  assert.strictEqual(this.timeoutType, TIMEOUT_HEADERS)
710
713
 
711
714
  this.statusCode = statusCode
712
- this.shouldKeepAlive = shouldKeepAlive
715
+ this.shouldKeepAlive = (
716
+ shouldKeepAlive ||
717
+ // Override llhttp value which does not allow keepAlive for HEAD.
718
+ (request.method === 'HEAD' && !socket[kReset] && this.connection.toLowerCase() === 'keep-alive')
719
+ )
713
720
 
714
721
  if (this.statusCode >= 200) {
715
722
  const bodyTimeout = request.bodyTimeout != null
@@ -739,7 +746,7 @@ class Parser {
739
746
  this.headers = []
740
747
  this.headersSize = 0
741
748
 
742
- if (shouldKeepAlive && client[kPipelining]) {
749
+ if (this.shouldKeepAlive && client[kPipelining]) {
743
750
  const keepAliveTimeout = this.keepAlive ? util.parseKeepAliveTimeout(this.keepAlive) : null
744
751
 
745
752
  if (keepAliveTimeout != null) {
@@ -769,7 +776,6 @@ class Parser {
769
776
  }
770
777
 
771
778
  if (request.method === 'HEAD') {
772
- assert(socket[kReset])
773
779
  return 1
774
780
  }
775
781
 
@@ -843,6 +849,7 @@ class Parser {
843
849
  this.bytesRead = 0
844
850
  this.contentLength = ''
845
851
  this.keepAlive = ''
852
+ this.connection = ''
846
853
 
847
854
  assert(this.headers.length % 2 === 0)
848
855
  this.headers = []
@@ -1376,8 +1383,8 @@ function write (client, request) {
1376
1383
  socket[kReset] = true
1377
1384
  }
1378
1385
 
1379
- if (reset) {
1380
- socket[kReset] = true
1386
+ if (reset != null) {
1387
+ socket[kReset] = reset
1381
1388
  }
1382
1389
 
1383
1390
  if (client[kMaxRequests] && socket[kCounter]++ >= client[kMaxRequests]) {
@@ -144,7 +144,7 @@ class Request {
144
144
 
145
145
  this.blocking = blocking == null ? false : blocking
146
146
 
147
- this.reset = reset == null ? false : reset
147
+ this.reset = reset == null ? null : reset
148
148
 
149
149
  this.host = null
150
150
 
@@ -259,7 +259,7 @@ function makeEntry (name, value, filename) {
259
259
  lastModified: value.lastModified
260
260
  }
261
261
 
262
- value = value instanceof File
262
+ value = (NativeFile && value instanceof NativeFile) || value instanceof UndiciFile
263
263
  ? new File([value], filename, options)
264
264
  : new FileLike(value, filename, options)
265
265
  }
@@ -309,23 +309,14 @@ class WebSocket extends EventTarget {
309
309
  // not throw an exception must increase the bufferedAmount attribute
310
310
  // by the length of data’s buffer in bytes.
311
311
 
312
- const ab = new ArrayBuffer(data.byteLength)
312
+ const ab = Buffer.from(data, data.byteOffset, data.byteLength)
313
313
 
314
- if (Buffer.isBuffer(data)) {
315
- // new Buffer signature is deprecated
316
- Buffer.from(ab).set(data)
317
- } else {
318
- new data.constructor(ab).set(data)
319
- }
320
-
321
- const value = Buffer.from(ab)
322
-
323
- const frame = new WebsocketFrameSend(value)
314
+ const frame = new WebsocketFrameSend(ab)
324
315
  const buffer = frame.createFrame(opcodes.BINARY)
325
316
 
326
- this.#bufferedAmount += value.byteLength
317
+ this.#bufferedAmount += ab.byteLength
327
318
  socket.write(buffer, () => {
328
- this.#bufferedAmount -= value.byteLength
319
+ this.#bufferedAmount -= ab.byteLength
329
320
  })
330
321
  } else if (isBlobLike(data)) {
331
322
  // If the WebSocket connection is established, and the WebSocket
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "undici",
3
- "version": "5.15.0",
3
+ "version": "5.15.1",
4
4
  "description": "An HTTP/1.1 client, written from scratch for Node.js",
5
5
  "homepage": "https://undici.nodejs.org",
6
6
  "bugs": {