From a08be18d361e50572d5fb06150ce55c7288f7c4f Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 2 May 2021 23:16:56 +0800 Subject: [PATCH 1/2] fix bug for websocket with poxy (https://github.com/JuliaWeb/HTTP.jl/issues/705) --- src/ConnectionRequest.jl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/ConnectionRequest.jl b/src/ConnectionRequest.jl index 15acffa1b..e389d39ab 100644 --- a/src/ConnectionRequest.jl +++ b/src/ConnectionRequest.jl @@ -64,7 +64,6 @@ function request(::Type{ConnectionPoolLayer{Next}}, url::URI, req, body; proxy=getproxy(url.scheme, url.host), socket_type::Type=TCPSocket, reuse_limit::Int=ConnectionPool.nolimit, kw...) where Next - if proxy !== nothing target_url = url url = URI(proxy) @@ -93,22 +92,28 @@ function request(::Type{ConnectionPoolLayer{Next}}, url::URI, req, body; end try - if proxy !== nothing && target_url.scheme == "https" + if proxy !== nothing && target_url.scheme in ("https", "wss", "ws") # tunnel request - target_url = merge(target_url, port=443) + if target_url.scheme in ("https", "wss") + target_url = merge(target_url, port=443) + elseif target_url.scheme in ("ws", ) && target_url.port == "" + target_url = merge(target_url, port=80) + end r = connect_tunnel(io, target_url, req) if r.status != 200 close(io) return r end - io = ConnectionPool.sslupgrade(io, target_url.host; kw...) + if target_url.scheme in ("https", "wss") + io = ConnectionPool.sslupgrade(io, target_url.host; kw...) + end req.headers = filter(x->x.first != "Proxy-Authorization", req.headers) end r = request(Next, io, req, body; kw...) if (io.sequence >= reuse_limit - || (proxy !== nothing && target_url.scheme == "https")) + || (proxy !== nothing && target_url.scheme in ("https", "wss", "ws"))) close(io) end From 277bca27f5836dc6fa6fefb6c341d3898bd77906 Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 2 May 2021 23:19:26 +0800 Subject: [PATCH 2/2] websocket proxy bug comment --- src/ConnectionRequest.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ConnectionRequest.jl b/src/ConnectionRequest.jl index e389d39ab..64268209f 100644 --- a/src/ConnectionRequest.jl +++ b/src/ConnectionRequest.jl @@ -97,7 +97,7 @@ function request(::Type{ConnectionPoolLayer{Next}}, url::URI, req, body; if target_url.scheme in ("https", "wss") target_url = merge(target_url, port=443) elseif target_url.scheme in ("ws", ) && target_url.port == "" - target_url = merge(target_url, port=80) + target_url = merge(target_url, port=80) # if there is no port info, connect_tunnel will fail end r = connect_tunnel(io, target_url, req) if r.status != 200