Skip to content

Add support for HTTPS proxy (again) - #372

Draft
rhenium wants to merge 4 commits into
ruby:masterfrom
rhenium:ky/rework-https-proxy
Draft

rhenium wants to merge 4 commits into
ruby:masterfrom
rhenium:ky/rework-https-proxy

Conversation

@rhenium

@rhenium rhenium commented Nov 27, 2026

Copy link
Copy Markdown
Member

Fixes #212

#55 was merged while the code was still unfinished. As pointed out in the linked issue above, it current works for neither HTTP requests nor HTTPS requests.

This PR attempts to actually implement it.


(First two commits are from #303)

Add Net::HTTP#proxy_use_ssl= to connect to the proxy server over TLS, and Net::HTTP#proxy_ssl_context to configure the TLS settings.

Also enable TLS automatically when the proxy setting taken from the environment variables has the https scheme.

Making HTTPS requests through an HTTPS proxy requires ruby/openssl 4.1, which supports nesting OpenSSL::SSL::SSLSocket objects.

This PR depends on ruby/openssl#736, which should be merged soon.

Add a new test case to confirm the current behavior.

Commit fa68e64 fixed the handling of certificate identity check
when connecting to an IP address, but the happy path is currently not
covered by the test suite.
Add Net::HTTP#ssl_context to return the SSLContext used for HTTPS
connections to allow users to configure it directly.

Also change the existing SSL/TLS-related accessors to forward to the
SSLContext instance directly rather than storing values in Net::HTTP's
instance variables and applying them later in Net::HTTP#start. This
avoids inconsistencies between, for example, http.cert_store and
http.ssl_context.cert_store.

The SSLContext instance is now reused for all connections made by a
Net::HTTP instance. As a result, the SSLContext becomes frozen on the
first connection attempt, and SSL/TLS-related options can no longer be
changed afterward. Although I do not expect this to affect most users,
it is technically a breaking change.

[Feature #19641]
This reverts commit ae2d83f.

The commit is very incomplete and not actually usable.
Add Net::HTTP#proxy_use_ssl= to connect to the proxy server over TLS,
and Net::HTTP#proxy_ssl_context to configure the TLS settings.

Also enable TLS automatically when the proxy setting taken from the
environment variables has the https scheme.

Making HTTPS requests through an HTTPS proxy requires ruby/openssl 4.1,
which supports nesting OpenSSL::SSL::SSLSocket objects.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Is the HTTPS proxy support known-working under real-world conditions?

1 participant