From bbed0103e1b42bdbfc0b5bc19d4f879dead4608e Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Thu, 21 Mar 2024 10:55:25 +0000 Subject: [PATCH] rewrite http proxy layer to accomodate https proxies it should test both http ad https requests over an http proxy, and http and http2 requests over an https proxy --- test/support/requests/plugins/proxy.rb | 42 +++++++++++++++----------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/test/support/requests/plugins/proxy.rb b/test/support/requests/plugins/proxy.rb index ba6c5a8c..cff1531d 100644 --- a/test/support/requests/plugins/proxy.rb +++ b/test/support/requests/plugins/proxy.rb @@ -18,14 +18,32 @@ module Requests end def test_plugin_http_http_proxy - return unless origin.start_with?("http://") + HTTPX.plugin(SessionWithPool) + .plugin(ProxyResponseDetector) + .plugin(:proxy, fallback_protocol: "http/1.1") + .with_proxy(uri: http_proxy).wrap do |session| + uri = build_uri("/get") + response = session.get(uri) + verify_status(response, 200) + verify_body_length(response) + assert response.proxied? - session = HTTPX.plugin(:proxy, fallback_protocol: "http/1.1").plugin(ProxyResponseDetector).with_proxy(uri: http_proxy) - uri = build_uri("/get") - response = session.get(uri) - verify_status(response, 200) - verify_body_length(response) - assert response.proxied? + conn = session.pool.connections.first + assert conn.io.is_a?(HTTPX::TCP) + end + end + + def test_plugin_http_https_proxy + HTTPX.plugin(SessionWithPool).plugin(ProxyResponseDetector).plugin(:proxy).with_proxy(uri: https_proxy).wrap do |session| + uri = build_uri("/get") + response = session.get(uri) + verify_status(response, 200) + verify_body_length(response) + assert response.proxied? + + conn = session.pool.connections.first + assert conn.io.is_a?(HTTPX::SSL) + end end def test_plugin_http_no_proxy @@ -59,16 +77,6 @@ module Requests assert response.proxied? end - def test_plugin_https_connect_http1_proxy - # return unless origin.start_with?("https://") - session = HTTPX.plugin(:proxy).plugin(ProxyResponseDetector).with_proxy(uri: http_proxy) - uri = build_uri("/get") - response = session.get(uri) - verify_status(response, 200) - verify_body_length(response) - assert response.proxied? - end - # TODO: uncomment when supporting H2 CONNECT # def test_plugin_https_connect_h2_proxy # return unless origin.start_with?("https://")