@@ -562,24 +562,24 @@ end
562
562
563
563
@testset " HTTP CONNECT Proxy pool" begin
564
564
function forwardclosetask (src, dst)
565
- errormonitor ( @async begin
565
+ @async begin
566
566
forwardstream (src, dst)
567
567
close (src)
568
568
close (dst)
569
- end )
569
+ end
570
570
end
571
571
572
572
# Stores the http message passed by the client
573
- messages = []
574
- upstreams = Set ()
573
+ downstreamcount = 0
574
+ upstreamsockets = Base . IdSet {TCPSocket} ()
575
575
576
576
# Simple implementation of a https proxy server
577
577
proxy = HTTP. listen! (IPv4 (0 ), 8082 ; stream = true ) do http:: HTTP.Stream
578
- push! (messages, http . message)
578
+ downstreamcount += 1
579
579
580
580
hostport = split (http. message. target, " :" )
581
581
targetstream = connect (hostport[1 ], parse (Int, get (hostport, 2 , " 443" )))
582
- push! (upstreams , targetstream)
582
+ push! (upstreamsockets , targetstream)
583
583
try
584
584
HTTP. setstatus (http, 200 )
585
585
HTTP. startwrite (http)
@@ -589,25 +589,23 @@ end
589
589
wait (up)
590
590
wait (down)
591
591
finally
592
- delete! (upstreams , targetstream)
592
+ delete! (upstreamsockets , targetstream)
593
593
end
594
594
end
595
595
596
596
try
597
597
# Make the HTTP request
598
598
r1 = HTTP. get (" https://$httpbin /ip" ; proxy= " http://localhost:8082" , retry= false , status_exception= true )
599
- @test length (messages) == 1
600
- @test first (messages). method == " CONNECT"
601
- @test length (upstreams) == 1 && isopen (first (upstreams)) # still alive
599
+ @test downstreamcount == 1
600
+ @test length (upstreamsockets) == 1 && isopen (first (upstreamsockets)) # still alive
602
601
603
602
# Make another request
604
603
# This should reuse the connection pool and not make another request to the proxy
605
- empty! (messages)
606
604
r2 = HTTP. get (" https://$httpbin /ip" ; proxy= " http://localhost:8082" , retry= false , status_exception= true )
607
- @test isempty (messages) # no new message to the proxy
608
- @test length (upstreams ) == 1 && isopen (first (upstreams )) # still only one stream alive
605
+ @test downstreamcount == 1 # no new message to the proxy
606
+ @test length (upstreamsockets ) == 1 && isopen (first (upstreamsockets )) # still only one stream alive
609
607
finally
610
- close .(upstreams )
608
+ close .(upstreamsockets )
611
609
close (proxy)
612
610
HTTP. Connections. closeall ()
613
611
wait (proxy)
@@ -616,20 +614,23 @@ end
616
614
617
615
@testset " HTTP Proxy pool" begin
618
616
# Stores the http request passed by the client
619
- downstreamconnections = Set {HTTP.Connections.Connection} ()
620
- upstreamconnections = Set {HTTP.Connections.Connection} ()
621
- finished_request = Base. Event (true )
617
+ downstreamconnections = Base. IdSet {HTTP.Connections.Connection} ()
618
+ upstreamconnections = Base. IdSet {HTTP.Connections.Connection} ()
619
+ downstreamcount = 0
620
+ upstreamcount = 0
622
621
623
622
# Simple implementation of a http proxy server
624
623
proxy = HTTP. listen! (IPv4 (0 ), 8082 ; stream = true ) do http:: HTTP.Stream
625
624
push! (downstreamconnections, http. stream)
625
+ downstreamcount += 1
626
626
627
627
HTTP. open (http. message. method, http. message. target, http. message. headers;
628
628
decompress = false , version = http. message. version, retry= false ,
629
629
redirect = false ) do targetstream
630
630
push! (upstreamconnections, targetstream. stream)
631
+ upstreamcount += 1
631
632
632
- up = errormonitor ( @async forwardstream (http, targetstream) )
633
+ up = @async forwardstream (http, targetstream)
633
634
targetresponse = startread (targetstream)
634
635
635
636
HTTP. setstatus (http, targetresponse. status)
@@ -638,30 +639,30 @@ end
638
639
end
639
640
640
641
HTTP. startwrite (http)
641
- down = errormonitor (@async forwardstream (targetstream, http))
642
+ down = Base . errormonitor (@async forwardstream (targetstream, http))
642
643
643
644
wait (up)
644
645
wait (down)
645
-
646
- notify (finished_request)
647
646
end
648
647
end
649
648
650
649
try
651
650
# Make the HTTP request
652
651
r1 = HTTP. get (" http://$httpbin /ip" ; proxy= " http://localhost:8082" , retry= false , redirect = false , status_exception= true )
653
- wait (finished_request)
654
652
@test length (downstreamconnections) == 1
655
653
@test length (upstreamconnections) == 1
654
+ @test downstreamcount == 1
655
+ @test upstreamcount == 1
656
656
657
657
# Make another request
658
658
# This should reuse a connection pool in both the client and proxy
659
659
r2 = HTTP. get (" http://$httpbin /ip" ; proxy= " http://localhost:8082" , retry= false , redirect = false , status_exception= true )
660
660
661
- # Check that notify was actually called, but that the set of connections remains of size 1
662
- wait (finished_request)
661
+ # Check that the set of connections remains of size 1 when handling additional requests downstream and upstream
663
662
@test length (downstreamconnections) == 1
664
663
@test length (upstreamconnections) == 1
664
+ @test downstreamcount == 2
665
+ @test upstreamcount == 2
665
666
finally
666
667
close (proxy)
667
668
HTTP. Connections. closeall ()
0 commit comments