follow-redirects 1.13.2 → 1.13.3
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 +39 -18
- package/package.json +1 -1
package/index.js
CHANGED
@@ -61,6 +61,17 @@ function RedirectableRequest(options, responseCallback) {
|
|
61
61
|
}
|
62
62
|
RedirectableRequest.prototype = Object.create(Writable.prototype);
|
63
63
|
|
64
|
+
RedirectableRequest.prototype.abort = function () {
|
65
|
+
// Abort the internal request
|
66
|
+
this._currentRequest.removeAllListeners();
|
67
|
+
this._currentRequest.on("error", noop);
|
68
|
+
this._currentRequest.abort();
|
69
|
+
|
70
|
+
// Abort this request
|
71
|
+
this.emit("abort");
|
72
|
+
this.removeAllListeners();
|
73
|
+
};
|
74
|
+
|
64
75
|
// Writes buffered data to the current native request
|
65
76
|
RedirectableRequest.prototype.write = function (data, encoding, callback) {
|
66
77
|
// Writing is not allowed if end has been called
|
@@ -140,18 +151,39 @@ RedirectableRequest.prototype.removeHeader = function (name) {
|
|
140
151
|
|
141
152
|
// Global timeout for all underlying requests
|
142
153
|
RedirectableRequest.prototype.setTimeout = function (msecs, callback) {
|
154
|
+
var self = this;
|
143
155
|
if (callback) {
|
144
|
-
this.
|
156
|
+
this.on("timeout", callback);
|
145
157
|
}
|
146
158
|
|
159
|
+
// Sets up a timer to trigger a timeout event
|
160
|
+
function startTimer() {
|
161
|
+
if (self._timeout) {
|
162
|
+
clearTimeout(self._timeout);
|
163
|
+
}
|
164
|
+
self._timeout = setTimeout(function () {
|
165
|
+
self.emit("timeout");
|
166
|
+
clearTimer();
|
167
|
+
}, msecs);
|
168
|
+
}
|
169
|
+
|
170
|
+
// Prevent a timeout from triggering
|
171
|
+
function clearTimer() {
|
172
|
+
clearTimeout(this._timeout);
|
173
|
+
if (callback) {
|
174
|
+
self.removeListener("timeout", callback);
|
175
|
+
}
|
176
|
+
if (!this.socket) {
|
177
|
+
self._currentRequest.removeListener("socket", startTimer);
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
// Start the timer when the socket is opened
|
147
182
|
if (this.socket) {
|
148
|
-
startTimer(
|
183
|
+
startTimer();
|
149
184
|
}
|
150
185
|
else {
|
151
|
-
|
152
|
-
this._currentRequest.once("socket", function () {
|
153
|
-
startTimer(self, msecs);
|
154
|
-
});
|
186
|
+
this._currentRequest.once("socket", startTimer);
|
155
187
|
}
|
156
188
|
|
157
189
|
this.once("response", clearTimer);
|
@@ -160,20 +192,9 @@ RedirectableRequest.prototype.setTimeout = function (msecs, callback) {
|
|
160
192
|
return this;
|
161
193
|
};
|
162
194
|
|
163
|
-
function startTimer(request, msecs) {
|
164
|
-
clearTimeout(request._timeout);
|
165
|
-
request._timeout = setTimeout(function () {
|
166
|
-
request.emit("timeout");
|
167
|
-
}, msecs);
|
168
|
-
}
|
169
|
-
|
170
|
-
function clearTimer() {
|
171
|
-
clearTimeout(this._timeout);
|
172
|
-
}
|
173
|
-
|
174
195
|
// Proxy all other public ClientRequest methods
|
175
196
|
[
|
176
|
-
"
|
197
|
+
"flushHeaders", "getHeader",
|
177
198
|
"setNoDelay", "setSocketKeepAlive",
|
178
199
|
].forEach(function (method) {
|
179
200
|
RedirectableRequest.prototype[method] = function (a, b) {
|