diff options
-rw-r--r-- | src/feature_flags.zig | 6 | ||||
-rw-r--r-- | src/http_client_async.zig | 8 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/feature_flags.zig b/src/feature_flags.zig index aec64dee1..692ee6c1d 100644 --- a/src/feature_flags.zig +++ b/src/feature_flags.zig @@ -98,3 +98,9 @@ pub const latin1_is_now_ascii = false; pub const http_buffer_pooling = true; pub const disable_lolhtml = false; + +/// There is, what I think is, a bug in getaddrinfo() +/// on macOS that specifically impacts localhost and not +/// other ipv4 hosts. This is a workaround for that. +/// "localhost" fails to connect. +pub const hardcode_localhost_to_127_0_0_1 = env.isMac; diff --git a/src/http_client_async.zig b/src/http_client_async.zig index 52f62d473..4f582d10d 100644 --- a/src/http_client_async.zig +++ b/src/http_client_async.zig @@ -252,7 +252,12 @@ fn NewHTTPContext(comptime ssl: bool) type { return null; } - pub fn connect(this: *@This(), client: *HTTPClient, hostname: []const u8, port: u16) !HTTPSocket { + pub fn connect(this: *@This(), client: *HTTPClient, hostname_: []const u8, port: u16) !HTTPSocket { + const hostname = if (FeatureFlags.hardcode_localhost_to_127_0_0_1 and strings.eqlComptime(hostname_, "localhost")) + "127.0.0.1" + else + hostname_; + if (this.existingSocket(hostname, port)) |sock| { sock.ext(**anyopaque).?.* = bun.cast(**anyopaque, ActiveSocket.init(client).ptr()); client.onOpen(comptime ssl, sock); @@ -1715,6 +1720,7 @@ pub fn handleResponseMetadata( if (location.len > url_buf.data.len) { return error.RedirectURLTooLong; } + deferred_redirect.* = this.redirect; std.mem.copy(u8, &url_buf.data, location); this.url = URL.parse(url_buf.data[0..location.len]); |