mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-12-04 00:01:13 -05:00
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:
parent
244563720a
commit
afbde420a7
@ -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
|
||||
|
||||
42
regression_tests/bug_0_24_1_test.rb
Normal file
42
regression_tests/bug_0_24_1_test.rb
Normal 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
|
||||
Loading…
x
Reference in New Issue
Block a user