From e5c60d05497f401f20fff0a0b519bd8d564f3a86 Mon Sep 17 00:00:00 2001 From: Colin Caine Date: Wed, 8 May 2024 10:02:34 +0100 Subject: [PATCH] Fix 1172 The IOType was not being set correctly when using a proxy. --- src/clientlayers/ConnectionRequest.jl | 3 ++- test/client.jl | 30 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/clientlayers/ConnectionRequest.jl b/src/clientlayers/ConnectionRequest.jl index b91febfe..23881bf9 100644 --- a/src/clientlayers/ConnectionRequest.jl +++ b/src/clientlayers/ConnectionRequest.jl @@ -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 diff --git a/test/client.jl b/test/client.jl index 2b6e32ba..ad76ad9f 100644 --- a/test/client.jl +++ b/test/client.jl @@ -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