mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-07 00:05:02 -04:00
Merge branch 'issue-292' into 'master'
bookkeep pool connections on Session#wrap Closes #292 See merge request os85/httpx!326
This commit is contained in:
commit
067e32923c
@ -5,8 +5,6 @@ services:
|
||||
environment:
|
||||
- HTTPBIN_COALESCING_HOST=another
|
||||
- HTTPX_RESOLVER_URI=https://doh/dns-query
|
||||
links:
|
||||
- "nghttp2:another"
|
||||
depends_on:
|
||||
- doh
|
||||
|
||||
|
@ -5,8 +5,6 @@ services:
|
||||
environment:
|
||||
- HTTPBIN_COALESCING_HOST=another
|
||||
- HTTPX_RESOLVER_URI=https://doh/dns-query
|
||||
links:
|
||||
- "nghttp2:another"
|
||||
depends_on:
|
||||
- doh
|
||||
|
||||
|
@ -5,8 +5,6 @@ services:
|
||||
environment:
|
||||
- HTTPBIN_COALESCING_HOST=another
|
||||
- HTTPX_RESOLVER_URI=https://doh/dns-query
|
||||
links:
|
||||
- "nghttp2:another"
|
||||
depends_on:
|
||||
- doh
|
||||
|
||||
|
@ -5,8 +5,6 @@ services:
|
||||
environment:
|
||||
- HTTPBIN_COALESCING_HOST=another
|
||||
- HTTPX_RESOLVER_URI=https://doh/dns-query
|
||||
links:
|
||||
- "nghttp2:another"
|
||||
depends_on:
|
||||
- doh
|
||||
|
||||
|
@ -5,8 +5,6 @@ services:
|
||||
environment:
|
||||
- HTTPBIN_COALESCING_HOST=another
|
||||
- HTTPX_RESOLVER_URI=https://doh/dns-query
|
||||
links:
|
||||
- "nghttp2:another"
|
||||
depends_on:
|
||||
- doh
|
||||
|
||||
|
@ -37,11 +37,9 @@ services:
|
||||
- aws
|
||||
- ws-echo-server
|
||||
- webdav
|
||||
- altsvc-nghttp2
|
||||
volumes:
|
||||
- ./:/home
|
||||
links:
|
||||
- "altsvc-nghttp2:another2"
|
||||
- "aws:test.aws"
|
||||
entrypoint:
|
||||
/home/test/support/ci/build.sh
|
||||
|
||||
@ -51,8 +49,6 @@ services:
|
||||
- ./test/support/ssh:/config
|
||||
depends_on:
|
||||
- nghttp2
|
||||
links:
|
||||
- "nghttp2:another"
|
||||
|
||||
socksproxy:
|
||||
image: qautomatron/docker-3proxy
|
||||
@ -61,8 +57,6 @@ services:
|
||||
- "3129:3129"
|
||||
volumes:
|
||||
- ./test/support/ci:/etc/3proxy
|
||||
links:
|
||||
- "nghttp2:another"
|
||||
|
||||
httpproxy:
|
||||
image: sameersbn/squid:3.5.27-2
|
||||
@ -72,8 +66,6 @@ services:
|
||||
- ./test/support/ci/squid/proxy.conf:/etc/squid/squid.conf
|
||||
- ./test/support/ci/squid/proxy-users-basic.txt:/etc/squid/proxy-users-basic.txt
|
||||
- ./test/support/ci/squid/proxy-users-digest.txt:/etc/squid/proxy-users-digest.txt
|
||||
links:
|
||||
- "nghttp2:another"
|
||||
command:
|
||||
-d 3
|
||||
|
||||
@ -101,6 +93,10 @@ services:
|
||||
- ./test/support/ci:/home
|
||||
command:
|
||||
--conf /home/nghttp.conf --no-ocsp --frontend '*,80;no-tls' --frontend '*,443'
|
||||
networks:
|
||||
default:
|
||||
aliases:
|
||||
- another
|
||||
|
||||
altsvc-nghttp2:
|
||||
image: registry.gitlab.com/os85/httpx/nghttp2:1
|
||||
@ -115,7 +111,10 @@ services:
|
||||
- ./test/support/ci:/home
|
||||
command:
|
||||
--conf /home/nghttp.conf --no-ocsp --frontend '*,80;no-tls' --frontend '*,443' --altsvc "h2,443,nghttp2"
|
||||
|
||||
networks:
|
||||
default:
|
||||
aliases:
|
||||
- another2
|
||||
httpbin:
|
||||
environment:
|
||||
- DEBUG=True
|
||||
@ -133,6 +132,10 @@ services:
|
||||
- 4566:4566
|
||||
volumes:
|
||||
- ./test/support/ci/aws:/docker-entrypoint-initaws.d
|
||||
networks:
|
||||
default:
|
||||
aliases:
|
||||
- test.aws
|
||||
|
||||
ws-echo-server:
|
||||
environment:
|
||||
@ -146,4 +149,4 @@ services:
|
||||
environment:
|
||||
- AUTH_TYPE=Basic
|
||||
- USERNAME=user
|
||||
- PASSWORD=pass
|
||||
- PASSWORD=pass
|
||||
|
@ -19,6 +19,17 @@ module HTTPX
|
||||
@connections = []
|
||||
end
|
||||
|
||||
def wrap
|
||||
connections = @connections
|
||||
@connections = []
|
||||
|
||||
begin
|
||||
yield self
|
||||
ensure
|
||||
@connections.unshift(*connections)
|
||||
end
|
||||
end
|
||||
|
||||
def empty?
|
||||
@connections.empty?
|
||||
end
|
||||
|
@ -28,13 +28,15 @@ module HTTPX
|
||||
# http.get("https://wikipedia.com")
|
||||
# end # wikipedia connection closes here
|
||||
def wrap
|
||||
begin
|
||||
prev_persistent = @persistent
|
||||
@persistent = true
|
||||
yield self
|
||||
ensure
|
||||
@persistent = prev_persistent
|
||||
close unless @persistent
|
||||
prev_persistent = @persistent
|
||||
@persistent = true
|
||||
pool.wrap do
|
||||
begin
|
||||
yield self
|
||||
ensure
|
||||
@persistent = prev_persistent
|
||||
close unless @persistent
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -7,6 +7,8 @@ module HTTPX
|
||||
@selector: Selector
|
||||
@connections: Array[Connection]
|
||||
|
||||
def wrap: () { (instance) -> void } -> void
|
||||
|
||||
def empty?: () -> void
|
||||
|
||||
def next_tick: () -> void
|
||||
|
@ -37,6 +37,41 @@ module Requests
|
||||
assert options.persistent
|
||||
end
|
||||
|
||||
def test_persistent_with_wrap
|
||||
return unless origin.start_with?("https")
|
||||
|
||||
uri = build_uri("/get")
|
||||
session1 = HTTPX.plugin(:persistent)
|
||||
|
||||
begin
|
||||
pool = session1.send(:pool)
|
||||
|
||||
initial_size = pool.instance_variable_get(:@connections).size
|
||||
response = session1.get(uri)
|
||||
verify_status(response, 200)
|
||||
|
||||
connections = pool.instance_variable_get(:@connections)
|
||||
pool_size = connections.size
|
||||
assert pool_size == initial_size + 1
|
||||
|
||||
HTTPX.wrap do |s|
|
||||
response = s.get(uri)
|
||||
verify_status(response, 200)
|
||||
wrapped_connections = pool.instance_variable_get(:@connections)
|
||||
pool_size = wrapped_connections.size
|
||||
assert pool_size == 1
|
||||
assert (connections - wrapped_connections) == connections
|
||||
end
|
||||
|
||||
final_connections = pool.instance_variable_get(:@connections)
|
||||
pool_size = final_connections.size
|
||||
assert pool_size == initial_size + 1
|
||||
assert (connections - final_connections).empty?
|
||||
ensure
|
||||
session1.close
|
||||
end
|
||||
end
|
||||
|
||||
def test_persistent_retry_http2_goaway
|
||||
return unless origin.start_with?("https")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user