Skip to content

Commit a420907

Browse files
authored
Fix 1172 (#1174)
The IOType was not being set correctly when using a proxy.
1 parent c0e9d3d commit a420907

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/clientlayers/ConnectionRequest.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ function connectionlayer(handler)
110110
return r
111111
end
112112
if target_url.scheme in ("https", "wss")
113-
io = Connections.sslupgrade(socket_type_tls, io, target_url.host; readtimeout=readtimeout, kw...)
113+
InnerIOType = sockettype(target_url, socket_type, socket_type_tls, get(kw, :sslconfig, nothing))
114+
io = Connections.sslupgrade(InnerIOType, io, target_url.host; readtimeout=readtimeout, kw...)
114115
end
115116
req.headers = filter(x->x.first != "Proxy-Authorization", req.headers)
116117
end

test/client.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,36 @@ end
3333
@test_throws ArgumentError HTTP.get("https://$httpbin/ip", sslconfig=MbedTLS.SSLConfig(false), socket_type_tls=OpenSSL.SSLStream)
3434
end
3535

36+
@testset "issue 1172" begin
37+
# Connections through a proxy need to choose an IOType twice rather than
38+
# just once.
39+
# https://github.com/JuliaWeb/HTTP.jl/issues/1172
40+
41+
# This proxy accepts two requests, ignoring the content of the request and
42+
# returning 200 each time.
43+
proxy = listen(IPv4(0), 8082)
44+
try
45+
@async begin
46+
sock = accept(proxy)
47+
while isopen(sock)
48+
line = readline(sock)
49+
@show 1, line
50+
isempty(line) && break
51+
end
52+
write(sock, "HTTP/1.1 200\r\n\r\n")
53+
# Test that we receive something that looks like a client hello
54+
# (indicating that we tried to upgrade the connection to TLS)
55+
line = readline(sock)
56+
@test startswith(line, "\x16")
57+
end
58+
59+
@test_throws HTTP.RequestError HTTP.head("https://$httpbin.com"; proxy="http://localhost:8082", readtimeout=1, retry=false)
60+
finally
61+
close(proxy)
62+
HTTP.Connections.closeall()
63+
end
64+
end
65+
3666
@testset "@client macro" begin
3767
@eval module MyClient
3868
using HTTP

0 commit comments

Comments
 (0)