aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Ciro Spaciari <ciro.spaciari@gmail.com> 2023-05-11 18:25:21 -0300
committerGravatar GitHub <noreply@github.com> 2023-05-11 14:25:21 -0700
commit3530cfac68a616c88e4a7b19f5da29f79883c971 (patch)
tree6aebb31540e83531ea59fb2278fa9a24820cd330
parentbc7d0adcf94d65b9238c6cb0aceb38c86cc323b3 (diff)
downloadbun-3530cfac68a616c88e4a7b19f5da29f79883c971.tar.gz
bun-3530cfac68a616c88e4a7b19f5da29f79883c971.tar.zst
bun-3530cfac68a616c88e4a7b19f5da29f79883c971.zip
fix redirect: \'manual\' and setTimeout on node:http request (#2848)
-rw-r--r--src/bun.js/http.exports.js24
-rw-r--r--src/http_client_async.zig7
2 files changed, 23 insertions, 8 deletions
diff --git a/src/bun.js/http.exports.js b/src/bun.js/http.exports.js
index 137906a5d..dda9664bb 100644
--- a/src/bun.js/http.exports.js
+++ b/src/bun.js/http.exports.js
@@ -925,7 +925,7 @@ export class ClientRequest extends OutgoingMessage {
#fetchRequest;
#signal = null;
[kAbortController] = null;
-
+ #timeoutTimer = null;
#options;
#finished;
@@ -1183,7 +1183,7 @@ export class ClientRequest extends OutgoingMessage {
this.#reusedSocket = false;
this.#host = host;
this.#protocol = protocol;
-
+ this.#timeoutTimer = null;
const headersArray = ArrayIsArray(headers);
if (!headersArray) {
var headers = options.headers;
@@ -1258,9 +1258,25 @@ export class ClientRequest extends OutgoingMessage {
setNoDelay(noDelay = true) {
__DEBUG__ && debug(`${NODE_HTTP_WARNING}\n`, "WARN: ClientRequest.setNoDelay is a no-op");
}
+ [kClearTimeout]() {
+ if (this.#timeoutTimer) {
+ clearTimeout(this.#timeoutTimer);
+ this.#timeoutTimer = null;
+ }
+ }
+
+ setTimeout(msecs, callback) {
+ if (this.#timeoutTimer) return this;
+ if (callback) {
+ this.on("timeout", callback);
+ }
+
+ this.#timeoutTimer = setTimeout(async () => {
+ this.#timeoutTimer = null;
+ this[kAbortController]?.abort();
+ this.emit("timeout");
+ }, msecs);
- setTimeout(timeout, callback) {
- __DEBUG__ && debug(`${NODE_HTTP_WARNING}\n`, "WARN: ClientRequest.setTimeout is a no-op");
return this;
}
}
diff --git a/src/http_client_async.zig b/src/http_client_async.zig
index 3f8b6998f..87d59778e 100644
--- a/src/http_client_async.zig
+++ b/src/http_client_async.zig
@@ -2835,14 +2835,13 @@ pub fn handleResponseMetadata(
else => {},
}
} else if (this.redirect_type == FetchRedirect.@"error") {
+ // error out if redirect is not allowed
return error.UnexpectedRedirect;
- } else if (this.redirect_type == FetchRedirect.manual) {
- this.state.response_stage = if (this.state.transfer_encoding == .chunked) .body_chunk else .body;
- return false;
}
}
+ // if is no redirect or if is redirect == "manual" just proceed
this.state.response_stage = if (this.state.transfer_encoding == .chunked) .body_chunk else .body;
-
+ // if no body is expected we should stop processing
return this.method.hasBody() and (this.state.body_size > 0 or this.state.transfer_encoding == .chunked);
}