aboutsummaryrefslogtreecommitdiff
path: root/src/http_client_async.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-11-19 22:13:30 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-11-19 22:13:30 -0800
commitf8d9a8be875a62eab9f3a6a8ca1a5b230d3aa0be (patch)
treebe768af5bf5c0443d132644eaa67c7d19e17755d /src/http_client_async.zig
parent9c601542d0faf7d94c6828f3b7890e3eae9b957e (diff)
downloadbun-f8d9a8be875a62eab9f3a6a8ca1a5b230d3aa0be.tar.gz
bun-f8d9a8be875a62eab9f3a6a8ca1a5b230d3aa0be.tar.zst
bun-f8d9a8be875a62eab9f3a6a8ca1a5b230d3aa0be.zip
[fetch] Fix bug with redirects losing the port number
Diffstat (limited to 'src/http_client_async.zig')
-rw-r--r--src/http_client_async.zig22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/http_client_async.zig b/src/http_client_async.zig
index 384c9fa2f..b327dd70b 100644
--- a/src/http_client_async.zig
+++ b/src/http_client_async.zig
@@ -1892,18 +1892,26 @@ pub fn handleResponseMetadata(
} else {
var url_buf = URLBufferPool.get(default_allocator);
const original_url = this.url;
- this.url = URL.parse(std.fmt.bufPrint(
- &url_buf.data,
- "{s}://{s}{s}",
- .{ original_url.displayProtocol(), original_url.displayHostname(), location },
- ) catch return error.RedirectURLTooLong);
+ const port = original_url.getPortAuto();
+
+ if (port == original_url.getDefaultPort()) {
+ this.url = URL.parse(std.fmt.bufPrint(
+ &url_buf.data,
+ "{s}://{s}{s}",
+ .{ original_url.displayProtocol(), original_url.displayHostname(), location },
+ ) catch return error.RedirectURLTooLong);
+ } else {
+ this.url = URL.parse(std.fmt.bufPrint(
+ &url_buf.data,
+ "{s}://{s}:{d}{s}",
+ .{ original_url.displayProtocol(), original_url.displayHostname(), port, location },
+ ) catch return error.RedirectURLTooLong);
+ }
deferred_redirect.* = this.redirect;
this.redirect = url_buf;
}
- // Ensure we don't up ove
-
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/303
if (response.status_code == 303) {
this.method = .GET;