follow-redirects 1.5.1 → 1.5.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.
Potentially problematic release.
This version of follow-redirects might be problematic. Click here for more details.
- package/index.js +8 -0
- package/package.json +1 -1
package/index.js
CHANGED
@@ -61,11 +61,19 @@ RedirectableRequest.prototype.write = function (data, encoding, callback) {
|
|
61
61
|
if (!(typeof data === "string" || typeof data === "object" && ("length" in data))) {
|
62
62
|
throw new Error("data should be a string, Buffer or Uint8Array");
|
63
63
|
}
|
64
|
+
// Ignore empty buffers, since writing them doesn't invoke the callback
|
65
|
+
// https://github.com/nodejs/node/issues/22066
|
66
|
+
if (data.length === 0) {
|
67
|
+
callback();
|
68
|
+
return;
|
69
|
+
}
|
70
|
+
// Only write when we don't exceed the maximum body length
|
64
71
|
if (this._requestBodyLength + data.length <= this._options.maxBodyLength) {
|
65
72
|
this._requestBodyLength += data.length;
|
66
73
|
this._requestBodyBuffers.push({ data: data, encoding: encoding });
|
67
74
|
this._currentRequest.write(data, encoding, callback);
|
68
75
|
}
|
76
|
+
// Error when we exceed the maximum body length
|
69
77
|
else {
|
70
78
|
this.emit("error", new Error("Request body larger than maxBodyLength limit"));
|
71
79
|
this.abort();
|