Ruby open-uri: Configure Basic Proxy Authentication
Use open-uri’s proxy authentication option without mixing it with destination credentials or environment defaults.
Use open-uri's dedicated Basic proxy option for the intermediary account:
require 'open-uri'
body = URI.open(
'https://example.com/',
proxy_http_basic_authentication: [
'http://203.0.113.10:8080',
ENV.fetch('PROXY_USER'),
ENV.fetch('PROXY_PASSWORD')
],
open_timeout: 5,
read_timeout: 10
) { |response| response.read }Replace the documentation endpoint and obtain account values from the intended secret source. Avoid putting the password into a URL that an exception or support report may later print.
| OpenRead option | Use |
|---|---|
proxy_http_basic_authentication | Proxy address and its Basic username/password. |
proxy | Proxy selection without that combined authenticated option; supplying both raises an argument error. |
http_basic_authentication | Destination-server account. |
proxy: nil | Make this read direct despite environment defaults. |
Without an explicit proxy option, open-uri can use scheme-specific proxy environment variables. The authenticated option already includes its endpoint; it needs no second proxy value.
This interface handles Basic proxy authentication. A service requiring another mechanism needs a compatible client or approved integration. Keep HTTPS verification enabled, then inspect status/content as appropriate: a working proxy login does not establish that the destination returned the expected resource.