got 14.6.1 → 14.6.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.
|
@@ -107,7 +107,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
|
|
|
107
107
|
private _flushed;
|
|
108
108
|
private _aborted;
|
|
109
109
|
private _expectedContentLength?;
|
|
110
|
-
private
|
|
110
|
+
private _compressedBytesCount?;
|
|
111
111
|
private readonly _requestId;
|
|
112
112
|
private _requestInitialized;
|
|
113
113
|
constructor(url: UrlType, options?: OptionsType, defaults?: DefaultsType);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
|
3
|
-
import { Duplex
|
|
3
|
+
import { Duplex } from 'node:stream';
|
|
4
4
|
import http, { ServerResponse } from 'node:http';
|
|
5
|
+
import { byteLength } from 'byte-counter';
|
|
5
6
|
import timer from '@szmarczak/http-timer';
|
|
6
7
|
import CacheableRequest, { CacheError as CacheableCacheError, } from 'cacheable-request';
|
|
7
8
|
import decompressResponse from 'decompress-response';
|
|
@@ -37,17 +38,6 @@ const proxiedRequestEvents = [
|
|
|
37
38
|
'upgrade',
|
|
38
39
|
];
|
|
39
40
|
const noop = () => { };
|
|
40
|
-
/**
|
|
41
|
-
Stream transform that counts bytes passing through.
|
|
42
|
-
Used to track compressed bytes before decompression for content-length validation.
|
|
43
|
-
*/
|
|
44
|
-
class ByteCounter extends Transform {
|
|
45
|
-
count = 0;
|
|
46
|
-
_transform(chunk, _encoding, callback) {
|
|
47
|
-
this.count += chunk.length;
|
|
48
|
-
callback(null, chunk);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
41
|
export default class Request extends Duplex {
|
|
52
42
|
// @ts-expect-error - Ignoring for now.
|
|
53
43
|
['constructor'];
|
|
@@ -76,7 +66,7 @@ export default class Request extends Duplex {
|
|
|
76
66
|
_flushed = false;
|
|
77
67
|
_aborted = false;
|
|
78
68
|
_expectedContentLength;
|
|
79
|
-
|
|
69
|
+
_compressedBytesCount;
|
|
80
70
|
_requestId = generateRequestId();
|
|
81
71
|
// We need this because `this._request` if `undefined` when using cache
|
|
82
72
|
_requestInitialized = false;
|
|
@@ -473,9 +463,9 @@ export default class Request extends Duplex {
|
|
|
473
463
|
}
|
|
474
464
|
_checkContentLengthMismatch() {
|
|
475
465
|
if (this.options.strictContentLength && this._expectedContentLength !== undefined) {
|
|
476
|
-
// Use
|
|
466
|
+
// Use compressed bytes count when available (for compressed responses),
|
|
477
467
|
// otherwise use _downloadedSize (for uncompressed responses)
|
|
478
|
-
const actualSize = this.
|
|
468
|
+
const actualSize = this._compressedBytesCount ?? this._downloadedSize;
|
|
479
469
|
if (actualSize !== this._expectedContentLength) {
|
|
480
470
|
this._beforeError(new ReadError({
|
|
481
471
|
message: `Content-Length mismatch: expected ${this._expectedContentLength} bytes, received ${actualSize} bytes`,
|
|
@@ -578,9 +568,9 @@ export default class Request extends Duplex {
|
|
|
578
568
|
// When strictContentLength is enabled, track compressed bytes by listening to
|
|
579
569
|
// the native response's data events before decompression
|
|
580
570
|
if (options.strictContentLength) {
|
|
581
|
-
this.
|
|
571
|
+
this._compressedBytesCount = 0;
|
|
582
572
|
this._nativeResponse.on('data', (chunk) => {
|
|
583
|
-
this.
|
|
573
|
+
this._compressedBytesCount += byteLength(chunk);
|
|
584
574
|
});
|
|
585
575
|
}
|
|
586
576
|
response = decompressResponse(response);
|
|
@@ -1259,7 +1249,9 @@ export default class Request extends Duplex {
|
|
|
1259
1249
|
this._request.write(chunk, encoding, (error) => {
|
|
1260
1250
|
// The `!destroyed` check is required to prevent `uploadProgress` being emitted after the stream was destroyed
|
|
1261
1251
|
if (!error && !this._request.destroyed) {
|
|
1262
|
-
|
|
1252
|
+
// For strings, encode them first to measure the actual bytes that will be sent
|
|
1253
|
+
const bytes = typeof chunk === 'string' ? Buffer.from(chunk, encoding) : chunk;
|
|
1254
|
+
this._uploadedSize += byteLength(bytes);
|
|
1263
1255
|
const progress = this.uploadProgress;
|
|
1264
1256
|
if (progress.percent < 1) {
|
|
1265
1257
|
this.emit('uploadProgress', progress);
|
|
@@ -1528,7 +1528,6 @@ export default class Options {
|
|
|
1528
1528
|
_defaultAgent?: http.Agent | undefined;
|
|
1529
1529
|
auth?: string | null | undefined;
|
|
1530
1530
|
defaultPort?: number | string | undefined;
|
|
1531
|
-
hints?: import("dns").LookupOptions["hints"];
|
|
1532
1531
|
host?: string | null | undefined;
|
|
1533
1532
|
hostname?: string | null | undefined;
|
|
1534
1533
|
insecureHTTPParser?: boolean | undefined;
|
|
@@ -1540,7 +1539,8 @@ export default class Options {
|
|
|
1540
1539
|
signal?: AbortSignal | undefined;
|
|
1541
1540
|
socketPath?: string | undefined;
|
|
1542
1541
|
uniqueHeaders?: Array<string | string[]> | undefined;
|
|
1543
|
-
joinDuplicateHeaders?: boolean;
|
|
1542
|
+
joinDuplicateHeaders?: boolean | undefined;
|
|
1543
|
+
hints?: number | undefined;
|
|
1544
1544
|
ALPNCallback?: ((arg: {
|
|
1545
1545
|
servername: string;
|
|
1546
1546
|
protocols: string[];
|
|
@@ -781,7 +781,7 @@ export default class Options {
|
|
|
781
781
|
}
|
|
782
782
|
// Detect if URL is already absolute (has a protocol/scheme)
|
|
783
783
|
const valueString = value.toString();
|
|
784
|
-
const isAbsolute = is.urlInstance(value) || /^[a-z][a-z\d+.-]
|
|
784
|
+
const isAbsolute = is.urlInstance(value) || /^[a-z][a-z\d+.-]*:\/\//i.test(valueString);
|
|
785
785
|
// Only concatenate prefixUrl if the URL is relative
|
|
786
786
|
const urlString = isAbsolute ? valueString : `${this.prefixUrl}${valueString}`;
|
|
787
787
|
const url = new URL(urlString);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "got",
|
|
3
|
-
"version": "14.6.
|
|
3
|
+
"version": "14.6.2",
|
|
4
4
|
"description": "Human-friendly and powerful HTTP request library for Node.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/got",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@sindresorhus/is": "^7.0.1",
|
|
55
55
|
"@szmarczak/http-timer": "^5.0.1",
|
|
56
|
+
"byte-counter": "^0.1.0",
|
|
56
57
|
"cacheable-lookup": "^7.0.0",
|
|
57
58
|
"cacheable-request": "^13.0.12",
|
|
58
59
|
"decompress-response": "^10.0.0",
|