fix: define can_authenticate? on Authentication::Basic

Summary

HTTPX::Plugins::Authentication::Basic does not define can_authenticate?, but Plugins::Proxy::Parameters#can_authenticate? delegates to it. Any HTTP proxy that returns 407 Proxy Authentication Required with a Basic challenge therefore raises NoMethodError instead of triggering the intended re-authentication retry.

Reproduce

client = HTTPX
  .plugin(:proxy)
  .with_proxy(uri: "http://user:pass@proxy.example.com:8080")
client.get("https://example.org")
# => NoMethodError: undefined method 'can_authenticate?' for an instance of HTTPX::Plugins::Authentication::Basic

Cause

  • lib/httpx/plugins/proxy.rb:90-94Parameters#can_authenticate? delegates to @authenticator.can_authenticate?(*args).
  • lib/httpx/plugins/auth/basic.rbAuthentication::Basic only defines initialize and authenticate.
  • The 407-handling paths at lib/httpx/plugins/proxy/http.rb:33 and :156 invoke this for every Basic-auth HTTP proxy that ever issues a challenge.

Sibling auth classes Digest, Ntlm, and Socks5 all define can_authenticate?; only Basic is missing it. Likely origin: when http auth schemes were extracted from individual plugins for shared use by :proxy (commits 817a10a5 / be060326, May 2022), the can_authenticate? API was added to the others but not to Basic — perhaps because Basic doesn't itself need the challenge to compute a response.

Fix

Mirrors Authentication::Socks5#can_authenticate? — semantically the closest sibling, since both schemes are credential-presence based and don't parse the challenge string.

def can_authenticate?(*)
  @user && @password
end

Happy to add a unit test if useful — wasn't sure of the preferred location, since test/plugins/auth/ doesn't currently exist; point me at the right convention and I'll follow up.

Merge request reports

Loading