Skip to content

Commit

Permalink
Fix 1172
Browse files Browse the repository at this point in the history
The IOType was not being set correctly when using a proxy.
  • Loading branch information
cmcaine committed May 8, 2024
1 parent c0e9d3d commit e5c60d0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/clientlayers/ConnectionRequest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ function connectionlayer(handler)
return r
end
if target_url.scheme in ("https", "wss")
io = Connections.sslupgrade(socket_type_tls, io, target_url.host; readtimeout=readtimeout, kw...)
InnerIOType = sockettype(target_url, socket_type, socket_type_tls, get(kw, :sslconfig, nothing))
io = Connections.sslupgrade(InnerIOType, io, target_url.host; readtimeout=readtimeout, kw...)
end
req.headers = filter(x->x.first != "Proxy-Authorization", req.headers)
end
Expand Down
30 changes: 30 additions & 0 deletions test/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,36 @@ end
@test_throws ArgumentError HTTP.get("https://$httpbin/ip", sslconfig=MbedTLS.SSLConfig(false), socket_type_tls=OpenSSL.SSLStream)
end

@testset "issue 1172" begin
# Connections through a proxy need to choose an IOType twice rather than
# just once.
# https://github.com/JuliaWeb/HTTP.jl/issues/1172

# This proxy accepts two requests, ignoring the content of the request and
# returning 200 each time.
proxy = listen(IPv4(0), 8082)
try
@async begin
sock = accept(proxy)
while isopen(sock)
line = readline(sock)
@show 1, line
isempty(line) && break
end
write(sock, "HTTP/1.1 200\r\n\r\n")
# Test that we receive something that looks like a client hello
# (indicating that we tried to upgrade the connection to TLS)
line = readline(sock)
@test startswith(line, "\x16")
end

@test_throws HTTP.RequestError HTTP.head("https://$httpbin.com"; proxy="http://localhost:8082", readtimeout=1, retry=false)
finally
close(proxy)
HTTP.Connections.closeall()
end
end

@testset "@client macro" begin
@eval module MyClient
using HTTP
Expand Down

0 comments on commit e5c60d0

Please sign in to comment.