diff options
author | 2022-11-19 22:13:30 -0800 | |
---|---|---|
committer | 2022-11-19 22:13:30 -0800 | |
commit | f8d9a8be875a62eab9f3a6a8ca1a5b230d3aa0be (patch) | |
tree | be768af5bf5c0443d132644eaa67c7d19e17755d /src/http_client_async.zig | |
parent | 9c601542d0faf7d94c6828f3b7890e3eae9b957e (diff) | |
download | bun-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.zig | 22 |
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; |