Skip to content

feat: Add opt-in proxy option to the client - #581

Merged
gjtorikian merged 6 commits into
mainfrom
devin/1795220081-ruby-proxy-option
Nov 23, 2026
Merged

gjtorikian merged 6 commits into
mainfrom
devin/1795220081-ruby-proxy-option

Conversation

@ajay-k

@ajay-k ajay-k commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

Today the only way to send SDK traffic through a proxy is the http_proxy environment variable, which applies to every Net::HTTP client in the process. A customer asked for a way to set it per client so they can roll a proxy out gradually.

This adds an optional proxy setting, available on WorkOS::Client.new(proxy:), WorkOS.configure { |c| c.proxy = ... } and WorkOS::PublicClient.create(proxy:):

proxied = WorkOS::Client.new(api_key: "sk_...", proxy: "http://user:pass@proxy.example.com:8080")

Behavior:

  • Unset (default): nothing changes. BaseClient#build_http still calls Net::HTTP.new(host, port) with no proxy arguments, so http_proxy / no_proxy are read from the environment as before. Passing an explicit nil proxy address would have turned that lookup off, so it is deliberately avoided. The connection cache key is also unchanged for these clients.
  • Set: the proxy is always used for that client and takes precedence over the environment (no_proxy does not apply to it). Percent-encoded credentials in the URL are decoded before use.
  • Validation: only http:// URLs with a host are accepted (a String or URI::HTTP); anything else raises ArgumentError at construction. The error message never echoes the URL, since it can contain credentials. https:// proxy URLs are rejected because the net-http bundled with Ruby 3.3 cannot connect to a proxy over TLS. API traffic is still tunneled with CONNECT and encrypted end to end.
  • Connection pool: pooled connections are shared by every client on a thread, so connection_key now appends a SHA-256 of the proxy URL when one is set. Clients with different proxies can't reuse each other's connection, and credentials are not stored in the key.

Not included: a per-request request_options[:proxy] override. Per-client covers the gradual-rollout use case and keeps the change small.

Testing:

  • bundle exec rake test and bundle exec standardrb pass on Ruby 3.3, 3.4 and 4.0.
  • Ran against two local CONNECT proxies and the real api.workos.com on Ruby 3.3 and 4.0: an explicit proxy is used (with decoded credentials), two clients with different proxies each use their own, a client without proxy goes direct, a client without proxy still follows http_proxy, and an explicit proxy wins over http_proxy.

Documentation

Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.

[ ] Yes

The README has a new "Proxy" section; no API reference changes.

Link to Devin session: https://workos.devinenterprise.com/sessions/67a6ce68d6d4482eab98a872fb79f92e
Open in Devin Desktop: https://workos.devinenterprise.com/desktop/session/67a6ce68d6d4482eab98a872fb79f92e?variant=devin
Requested by: @ajay-k


🟢 Devin Review found nothing to fix · View findings · Follow Devin's work

Devin Review

Lets a single client route its requests through an HTTP proxy instead of relying on the process-wide http_proxy environment variable. When the option is unset, Net::HTTP keeps reading the proxy from the environment as before.

Co-Authored-By: Ajay Kumar <ajay.kumar@workos.com>
@ajay-k
ajay-k requested a review from a team as a code owner November 21, 2026 00:20
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

Original prompt from Ajay

investigate: https://app.plain.com/workspace/w_01KEZ48Y1GZPN4PXQ41666E911/thread/th_01M7XNJMG72QQMFETQJPKFCF1P/

@devin-ai-integration devin-ai-integration Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@greptile-apps

greptile-apps Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Adds an optional per-client HTTP proxy while preserving environment-based proxy settings when none is supplied.

  • Each WorkOS client can send its requests through an HTTP proxy.
  • Rejected proxy connections now reach callers as WorkOS connection errors.
  • Retry waits now follow HTTP-date values in Retry-After.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Client request] --> B{Explicit proxy?}
  B -->|Yes| C[Use configured HTTP proxy]
  B -->|No| D[Keep existing environment settings]
  C --> E[Pool connection by destination and proxy]
  D --> F[Keep existing connection key]
  E --> G[Send request]
  F --> G
  G -->|Connection fails| H[Remove connections for this route]
Loading

Reviews (5) · Last reviewed commit: "fix(client): Keep other routes pooled on..." · Reviewed by Greptile

greptile-apps[bot]

This comment was marked as resolved.

devin-ai-integration Bot and others added 2 commits November 21, 2026 00:26
Co-Authored-By: Ajay Kumar <ajay.kumar@workos.com>
A proxy that answers CONNECT with a non-2xx status makes Net::HTTP
raise while it opens the connection. Those exception classes were not
in the rescue list, so callers got a raw Net::HTTPClientException or
Net::HTTPFatalError instead of the WorkOS::APIConnectionError the
README tells them to rescue. A 503 from the proxy was also tried only
once, while a 503 from the API is retried.

These are the failures a proxy rollout is most likely to hit: bad
credentials (407), a host the proxy does not allow (403) and an
overloaded proxy (503). Clients that take their proxy from the
`http_proxy` environment variable had the same gap.

The proxy's status decides whether to retry, using the same list as
API responses. The request never left the process, so another
attempt is always safe.
devin-ai-integration[bot]

This comment was marked as resolved.

Retry-After is either a number of seconds or an HTTP-date (RFC 9110,
section 10.2.3). Only the number was read, so a date fell through to
the normal backoff and the client could use up its retries before the
server was ready again.

Devin Review raised this on the proxy CONNECT fix, because a 503 or
429 from a proxy now goes through the same delay calculation. The gap
is older than that fix and applied to every API response.

A date that is not in the future, or a value in neither form, still
falls back to the backoff.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

`WorkOS.configure` stored any proxy value, and the check only ran
when the first client was built. A typo in an initializer therefore
passed boot and surfaced as an ArgumentError on the first API
request.

The setter runs the same check as the client, so the two cannot
drift apart.
A failed request evicted every pooled connection to the host on that
thread, including the ones held by clients on another route. With a
proxied client and a direct client side by side, which is the gradual
rollout the proxy option exists for, each failure on one of them cost
the other a new TCP and TLS handshake.

Those connections use their own sockets, so the failure says nothing
about them. Eviction still covers every timeout on the client's own
route.
@gjtorikian
gjtorikian merged commit 399682a into main Nov 23, 2026
11 checks passed
@gjtorikian
gjtorikian deleted the devin/1795220081-ruby-proxy-option branch November 23, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants