got 12.0.3 → 12.0.4
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.
|
@@ -121,8 +121,6 @@ export default class Request extends Duplex implements RequestEvents<Request> {
|
|
|
121
121
|
end?: boolean;
|
|
122
122
|
}): T;
|
|
123
123
|
unpipe<T extends NodeJS.WritableStream>(destination: T): this;
|
|
124
|
-
private _lockWrite;
|
|
125
|
-
private _unlockWrite;
|
|
126
124
|
private _finalizeBody;
|
|
127
125
|
private _onResponseBase;
|
|
128
126
|
private _setRawBody;
|
|
@@ -201,24 +201,6 @@ export default class Request extends Duplex {
|
|
|
201
201
|
this.redirectUrls = [];
|
|
202
202
|
this.retryCount = 0;
|
|
203
203
|
this._stopRetry = noop;
|
|
204
|
-
const unlockWrite = () => {
|
|
205
|
-
this._unlockWrite();
|
|
206
|
-
};
|
|
207
|
-
const lockWrite = () => {
|
|
208
|
-
this._lockWrite();
|
|
209
|
-
};
|
|
210
|
-
this.on('pipe', (source) => {
|
|
211
|
-
source.prependListener('data', unlockWrite);
|
|
212
|
-
source.on('data', lockWrite);
|
|
213
|
-
source.prependListener('end', unlockWrite);
|
|
214
|
-
source.on('end', lockWrite);
|
|
215
|
-
});
|
|
216
|
-
this.on('unpipe', (source) => {
|
|
217
|
-
source.off('data', unlockWrite);
|
|
218
|
-
source.off('data', lockWrite);
|
|
219
|
-
source.off('end', unlockWrite);
|
|
220
|
-
source.off('end', lockWrite);
|
|
221
|
-
});
|
|
222
204
|
this.on('pipe', source => {
|
|
223
205
|
if (source.headers) {
|
|
224
206
|
Object.assign(this.options.headers, source.headers);
|
|
@@ -250,12 +232,9 @@ export default class Request extends Duplex {
|
|
|
250
232
|
};
|
|
251
233
|
return;
|
|
252
234
|
}
|
|
253
|
-
const { json, body, form } = this.options;
|
|
254
|
-
if (json || body || form) {
|
|
255
|
-
this._lockWrite();
|
|
256
|
-
}
|
|
257
235
|
// Important! If you replace `body` in a handler with another stream, make sure it's readable first.
|
|
258
236
|
// The below is run only once.
|
|
237
|
+
const { body } = this.options;
|
|
259
238
|
if (is.nodeStream(body)) {
|
|
260
239
|
body.once('error', error => {
|
|
261
240
|
if (this._flushed) {
|
|
@@ -492,17 +471,6 @@ export default class Request extends Duplex {
|
|
|
492
471
|
super.unpipe(destination);
|
|
493
472
|
return this;
|
|
494
473
|
}
|
|
495
|
-
_lockWrite() {
|
|
496
|
-
const onLockedWrite = () => {
|
|
497
|
-
throw new TypeError('The payload has been already provided');
|
|
498
|
-
};
|
|
499
|
-
this.write = onLockedWrite;
|
|
500
|
-
this.end = onLockedWrite;
|
|
501
|
-
}
|
|
502
|
-
_unlockWrite() {
|
|
503
|
-
this.write = super.write;
|
|
504
|
-
this.end = super.end;
|
|
505
|
-
}
|
|
506
474
|
async _finalizeBody() {
|
|
507
475
|
const { options } = this;
|
|
508
476
|
const { headers } = options;
|
|
@@ -563,12 +531,6 @@ export default class Request extends Duplex {
|
|
|
563
531
|
headers['content-length'] = String(uploadBodySize);
|
|
564
532
|
}
|
|
565
533
|
}
|
|
566
|
-
else if (cannotHaveBody) {
|
|
567
|
-
this._lockWrite();
|
|
568
|
-
}
|
|
569
|
-
else {
|
|
570
|
-
this._unlockWrite();
|
|
571
|
-
}
|
|
572
534
|
if (options.responseType === 'json' && !('accept' in options.headers)) {
|
|
573
535
|
options.headers.accept = 'application/json';
|
|
574
536
|
}
|
|
@@ -829,17 +791,12 @@ export default class Request extends Duplex {
|
|
|
829
791
|
}
|
|
830
792
|
})();
|
|
831
793
|
}
|
|
832
|
-
else {
|
|
833
|
-
this.
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
}
|
|
839
|
-
else if (this._cannotHaveBody || this._noPipe) {
|
|
840
|
-
currentRequest.end();
|
|
841
|
-
this._lockWrite();
|
|
842
|
-
}
|
|
794
|
+
else if (!is.undefined(body)) {
|
|
795
|
+
this._writeRequest(body, undefined, () => { });
|
|
796
|
+
currentRequest.end();
|
|
797
|
+
}
|
|
798
|
+
else if (this._cannotHaveBody || this._noPipe) {
|
|
799
|
+
currentRequest.end();
|
|
843
800
|
}
|
|
844
801
|
}
|
|
845
802
|
_prepareCache(cache) {
|