httpx/regression_tests/bug_1_3_1_test.rb
Alexey Romanov fda0ea8b0e Prevent NoMethodError in the proxy plugin
When:
1. the proxy is autodetected from `http_proxy` etc. variables;
2. a request is made which bypasses the proxy (e.g. to an authority in `no_proxy`);
3. this request fails with one of `Proxy::PROXY_ERRORS` (timeout or a system error)

the `fetch_response` method tried to access the proxy URIs array which
isn't initialized by `proxy_options`. This change fixes the
`proxy_error?` check to avoid the issue.
2024-10-21 10:10:12 +01:00

37 lines
795 B
Ruby

# frozen_string_literal: true
require "test_helper"
require "support/http_helpers"
require "webmock/minitest"
require "httpx/adapters/webmock"
class Bug_1_3_1_Test < Minitest::Test
include HTTPHelpers
def test_plugin_http_webmock_next_proxy
exception_class = Class.new(IOError)
stub_exception = stub_http_request(:any, "https://#{httpbin}/get").to_raise(exception_class.new("exception message"))
HTTPX.plugin(SessionWithPool).plugin(ProxyResponseDetector).plugin(:proxy).wrap do |http|
http.get("https://#{httpbin}/get")
assert_requested(stub_exception)
end
end
private
def scheme
"http://"
end
def setup
WebMock.enable!
WebMock.disable_net_connect!
end
def teardown
WebMock.allow_net_connect!
WebMock.disable!
end
end