From 6070e135e93cd705ff3eaf8a6b0ff0b4ec504818 Mon Sep 17 00:00:00 2001 From: Ciro Spaciari Date: Fri, 12 May 2023 08:06:17 -0300 Subject: [PATCH] fix proxy status return (#2860) --- src/http_client_async.zig | 10 +++++----- test/js/bun/http/proxy.test.js | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/http_client_async.zig b/src/http_client_async.zig index 87d59778ef..276186fe5c 100644 --- a/src/http_client_async.zig +++ b/src/http_client_async.zig @@ -2717,13 +2717,13 @@ pub fn handleResponseMetadata( } if (this.proxy_tunneling and this.proxy_tunnel == null) { - //proxy denied connection - if (this.state.pending_response.status_code != 200) { - return error.ConnectionRefused; + if (this.state.pending_response.status_code == 200) { + //signal to continue the proxing + return true; } - //signal to continue the proxing - return true; + //proxy denied connection so return proxy result (407, 403 etc) + this.proxy_tunneling = false; } const is_redirect = this.state.pending_response.status_code >= 300 and this.state.pending_response.status_code <= 399; diff --git a/test/js/bun/http/proxy.test.js b/test/js/bun/http/proxy.test.js index 203cbc2945..85bb7ecf35 100644 --- a/test/js/bun/http/proxy.test.js +++ b/test/js/bun/http/proxy.test.js @@ -116,9 +116,9 @@ it("proxy non-TLS auth can fail", async () => { { try { const response = await fetch(url, { verbose: true, proxy: `http://localhost:${auth_proxy.port}` }); - expect(response.statusText).toBe("Proxy Authentication Required"); + expect(response.status).toBe(407); } catch (err) { - expect(err).toBe("Proxy Authentication Required"); + expect(true).toBeFalsy(); } } @@ -128,9 +128,9 @@ it("proxy non-TLS auth can fail", async () => { verbose: true, proxy: `http://squid_user:asdf123@localhost:${auth_proxy.port}`, }); - expect(response.statusText).toBe("Forbidden"); + expect(response.status).toBe(403); } catch (err) { - expect(err).toBe("Forbidden"); + expect(true).toBeFalsy(); } } });