Skip to content

Commit 21b9ee6

Browse files
committed
broken test: https pool with proxy
1 parent f59d03b commit 21b9ee6

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

test/pool.jl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,61 @@ end
121121
end
122122
end
123123

124+
function readwriteclose(src, dst)
125+
try
126+
readwrite(src, dst)
127+
finally
128+
close(src)
129+
close(dst)
130+
end
131+
end
132+
133+
@testset "https pool with proxy" begin
134+
connectcount = 0
135+
136+
# Simple implementation of a connect proxy server
137+
proxy = HTTP.listen!(IPv4(0), 8082; stream = true) do http::HTTP.Stream
138+
@assert http.message.method == "CONNECT"
139+
connectcount += 1
140+
141+
hostport = split(http.message.target, ":")
142+
targetstream = connect(hostport[1], parse(Int, get(hostport, 2, "443")))
143+
144+
HTTP.setstatus(http, 200)
145+
HTTP.startwrite(http)
146+
up = @async readwriteclose(http.stream.io, targetstream)
147+
readwriteclose(targetstream, http.stream.io)
148+
wait(up)
149+
end
150+
151+
try
152+
function https_request_ip_through_proxy()
153+
r = HTTP.get("https://$httpbin/ip"; proxy="http://localhost:8082", retry=false, status_exception=true)
154+
String(r.body)
155+
end
156+
157+
@testset "Only one tunnel should be established with sequential requests" begin
158+
https_request_ip_through_proxy()
159+
https_request_ip_through_proxy()
160+
@test_broken connectcount == 1
161+
end
162+
163+
@testset "parallell tunnels should be established with parallell requests" begin
164+
n_asyncgetters = 3
165+
asyncgetters = [@async https_request_ip_through_proxy() for _ in 1:n_asyncgetters]
166+
wait.(asyncgetters)
167+
@test_broken connectcount == n_asyncgetters
168+
end
169+
170+
finally
171+
# Close pooled connections explicitly so the proxy handler can finish
172+
# Connections.closeall never closes anything
173+
close.(pooledconnections(HTTP.SOCKET_TYPE_TLS[]))
174+
175+
HTTP.Connections.closeall()
176+
close(proxy)
177+
wait(proxy)
178+
end
179+
end
180+
124181
end # module

0 commit comments

Comments
 (0)