proxy: fix incorrect connection #send definition never calling super

this made several plugins unusable with the proxy plugin, because a lot
of them are dependent on Connection#send being called and overwritten.
This was done so to avoid piping requests when intermediate
connect-level parsers are in place. So in the way, when the conn is
initial, original send is closed; when not, which should almost never
happen, a second list is created, which is then piped when the
connection is established, back to original send.
This commit is contained in:
HoneyryderChuck 2023-06-25 01:25:11 +01:00
parent 244563720a
commit afbde420a7
2 changed files with 52 additions and 3 deletions

View File

@ -267,10 +267,11 @@ module HTTPX
end
def send(request)
return super unless @options.proxy
return super unless connecting?
return super unless (
@options.proxy && @state != :idle && connecting?
)
@pending << request
(@proxy_pending ||= []) << request
end
def connecting?
@ -308,6 +309,12 @@ module HTTPX
when :idle
transition(:connecting)
when :connected
if @proxy_pending
while (req = @proxy_pendind.shift)
send(req)
end
end
transition(:open)
end
end

View File

@ -0,0 +1,42 @@
# frozen_string_literal: true
require "test_helper"
require "support/http_helpers"
require "support/proxy_helper"
require "support/minitest_extensions"
class Bug_0_24_1_Test < Minitest::Test
include HTTPHelpers
include ProxyHelper
Plugin = Module.new do
@requests = []
class << self
attr_accessor :requests
end
self::ConnectionMethods = Module.new do
def send(req)
Plugin.requests << req
super
end
end
end
def test_proxy_plugin_silencing_conn_send_based_plugin
http = HTTPX.plugin(Plugin).plugin(:proxy).plugin(ProxyResponseDetector).with_proxy(uri: http_proxy)
uri = build_uri("/get")
response = http.get(uri)
verify_status(response, 200)
assert response.proxied?
assert Plugin.requests.size == 1
end
private
def scheme
"http://"
end
end