Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug in websocket with proxy #708

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/ConnectionRequest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) # if there is no port info, connect_tunnel will fail
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

Expand Down