aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-09-11 14:59:48 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-09-11 14:59:48 -0700
commit0130efeedf4ff422196fb98b92499524f5336d3b (patch)
treebcf5530ecaee86bc2fd443470db6667072d97eb9 /src
parent35b51fcbb55631aa936a49698c7148aa505808da (diff)
downloadbun-0130efeedf4ff422196fb98b92499524f5336d3b.tar.gz
bun-0130efeedf4ff422196fb98b92499524f5336d3b.tar.zst
bun-0130efeedf4ff422196fb98b92499524f5336d3b.zip
Hardcode localhost on macOS
Diffstat (limited to 'src')
-rw-r--r--src/feature_flags.zig6
-rw-r--r--src/http_client_async.zig8
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]);