BeiBaiNian opened a new pull request, #205:
URL: https://github.com/apache/casbin-gateway/pull/205
## Why
the channel probe (the "Test connection" button in the channel admin UI,
which calls `object.TestChannelConnectivity`) and the `/v1/chat/completions`
forwarding requests ignore the `httpProxy` (SOCKS5) already configured in
`conf/app.conf`.
- The probe uses a bare `&http.Client{}` with the default transport, which
only honors environment proxies; in a data center that cannot reach
Google/OpenAI it just times out.
- The old `proxy` package had defects:
- `GetProxyDialer()` (proxy/proxy.go:93) does an always-panicking type
assertion — `x/net`'s `SOCKS5()` returns `*socks.Dialer`, not `*net.Dialer`.
- `getProxyHttpClient()` returned a bare `&http.Client{}` without timeouts
when the proxy liveness probe failed.
- `isAddressOpen` decided once at startup and never re-checked, so a proxy
that died at runtime was never recovered.
## What changed
- The `proxy` package now exposes a single entry point:
- Added `NewTransport()` / `ConfigureTransport(*http.Transport)`:
`app.conf` `httpProxy` takes precedence over environment variables; falls back
to `HTTP_PROXY` / `HTTPS_PROXY` when unset.
- Uses the stdlib `Transport.Proxy = http.ProxyURL(&url.URL{Scheme:
"socks5", Host: httpProxy})` (native `socks5` scheme since Go 1.9) instead of a
hand-rolled `x/net` dialer, net removing ~45 lines and dropping the
`golang.org/x/net/proxy` dependency.
- Removed the always-panicking `GetProxyDialer()` and the one-shot
`isAddressOpen()`; an explicitly configured proxy is now mandatory (no silent
fallback to direct); a `beego.Trace` log line confirms the proxy is active.
- Removed the meaningless `DefaultHttpClient` alias; its only caller now
uses the stdlib `http.DefaultClient`.
- `controllers/proxy.go`: the forwarding client is built lazily with
`sync.Once`, so package-level initialization can no longer freeze the proxy
policy before `app.conf` is loaded in embedded single-binary mode; keeps
connection pooling, 10s TCP dial, 60s response-header and SSE idle timeouts,
and redirect disabling.
- `object/channel.go`: `TestChannelConnectivity` (the "Test connection"
button) now uses `proxy.NewTransport()`; the 10s overall timeout and the
redirect policy are unchanged.
- `object/cert_whois.go`: removed a stale comment block referencing the
deleted function.
## Verification
- `go test ./proxy ./object ./certificate -run '^$'`: compiles clean.
- `go test -tags embed ./controllers ./object -run '^$'`: compiles clean in
embedded single-binary mode.
- With `httpProxy` set, the channel probe, `/v1/chat/completions` forwarding
and ACME requests all egress via the SOCKS5 proxy; without it, environment
proxies are used.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]