Skip to content

Commit 1323619

Browse files
committed
broken test: https pool with proxy
1 parent 087e445 commit 1323619

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
@@ -122,4 +122,61 @@ end
122122
end
123123
end
124124

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

0 commit comments

Comments
 (0)