diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/http_client_async.zig | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/http_client_async.zig b/src/http_client_async.zig index 89cedaa1b..3cc044003 100644 --- a/src/http_client_async.zig +++ b/src/http_client_async.zig @@ -3479,22 +3479,20 @@ pub fn handleResponseMetadata( this.redirect = url_buf; } else { var url_buf = URLBufferPool.get(default_allocator); + var fba = std.heap.FixedBufferAllocator.init(&url_buf.data); const original_url = this.url; - 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); + + const new_url_ = bun.JSC.URL.join( + bun.String.fromUTF8(original_url.href), + bun.String.fromUTF8(location), + ); + defer new_url_.deref(); + + if (new_url_.utf8ByteLength() > url_buf.data.len) { + return error.RedirectURLTooLong; } + const new_url = new_url_.toUTF8(fba.allocator()); + this.url = URL.parse(new_url.slice()); is_same_origin = strings.eqlCaseInsensitiveASCII(strings.withoutTrailingSlash(this.url.origin), strings.withoutTrailingSlash(original_url.origin), true); deferred_redirect.* = this.redirect; |
