Documentation
¶
Overview ¶
Package netproxy decides which proxy magpie's own requests to vendors go through. An app started from the Dock or the Start menu has no HTTPS_PROXY in its environment, so without this every call to a vendor that is only reachable through a proxy hangs until the agent gives up.
In order: the proxy set in magpie's settings (or "direct" for none), the usual *_PROXY variables, then the system's proxy (macOS network settings, Windows Internet Options). Loopback is never proxied, nor, unless a provider has a proxy of its own, a host on the user's own network (lan.go).
Index ¶
- Variables
- func Bridge(socks *url.URL) (string, error)
- func Choice(ctx context.Context) string
- func Describe() (proxy, source string)
- func DialSOCKS(ctx context.Context, socks *url.URL, addr string) (net.Conn, error)
- func Dispatch(base *http.Transport) http.RoundTripper
- func Env(env []string) []string
- func EnvForBun(env []string) []string
- func EnvWith(choice string, env []string) []string
- func For(u *url.URL) (*url.URL, error)
- func ForBun(proxy string) string
- func Func(req *http.Request) (*url.URL, error)
- func Held(ctx context.Context) error
- func Hold(ctx context.Context, err error) context.Context
- func Install()
- func IsSOCKS(u *url.URL) bool
- func Parse(s string) (*url.URL, error)
- func Redact(raw string) string
- func With(ctx context.Context, choice string) context.Context
- func WithUncheckedTLS(ctx context.Context, bases ...string) context.Context
- type Proxy
Constants ¶
This section is empty.
Variables ¶
var ErrUncheckedOverHTTPSProxy = errors.New("a provider whose certificate isn't checked can't be reached through an https:// proxy, whose certificate would go unchecked with it: give it an http:// or socks5:// proxy, or none")
ErrUncheckedOverHTTPSProxy is why a request to a host whose certificate is not checked isn't sent through an https:// proxy: the proxy's own TLS is dialled with the same config, so its certificate would go unchecked too.
var HTTP1 func(u *url.URL) bool
HTTP1 says a request to u goes over HTTP/1.1 only, whatever its transport offers. internal/provider sets it to the ChatGPT backend's host, which Codex itself speaks HTTP/1.1 to; nil leaves every request to its transport.
Functions ¶
func Bridge ¶ added in v0.1.584
Bridge is the http:// address of a proxy on loopback carrying what it is given through the SOCKS5 proxy socks, one for each, kept while magpie runs.
func Choice ¶ added in v0.1.427
Choice is the proxy ctx names (With), "" when it names none — for a CLI run on a provider's behalf, whose *_PROXY is set from it (EnvWith).
func Describe ¶
func Describe() (proxy, source string)
Describe says, for the settings page, what a request to u would use.
func DialSOCKS ¶ added in v0.1.584
DialSOCKS connects to addr (host:port) through the SOCKS5 proxy socks, the user and password in its address used when it has them. The host is sent by name, as Go's own transport sends it, so the proxy resolves it.
func Dispatch ¶ added in v0.1.418
func Dispatch(base *http.Transport) http.RoundTripper
Dispatch is a RoundTripper sending a request through base, unless its context names a provider's own proxy (With): then through a clone of base kept for that proxy alone. Connections are so reused among the requests going through one proxy and never carried to another — HTTP/2 ones, which a transport shares by host whatever proxy they were dialled through, among them. A request HTTP1 names goes through a clone kept for HTTP/1.1 (http1Only), and one to a host whose certificate the provider's user said not to check (WithUncheckedTLS) through a clone kept for that host alone (uncheckTLS). A host whose IPv6 is taken but goes nowhere is dialed over IPv4 (v4Fallback).
func Env ¶ added in v0.1.53
Env is env (the process's own when nil) for an agent's CLI that magpie starts — a sign-in, or a subscription's run — told to use the proxy magpie's own requests would: the CLI reads only *_PROXY, which an app started from the Dock or the Start menu doesn't have, so a proxy set in magpie or the system's alone left it trying the vendor directly. A proxy set in magpie replaces any in env and "direct" drops them; the system's is only added where env names none. Loopback never goes through it, since a CLI calls back to magpie there.
func EnvForBun ¶ added in v0.1.1139
EnvForBun is env for a bun that magpie starts (bun add, update, remove, run, or an agent CLI's bun add -g): its *_PROXY with a SOCKS5 one bridged (ForBun). Bun takes only http:// and https:// proxies, and with a socks5:// one every registry fetch failed as UnsupportedProxyProtocol (#1409), which a Mac with only a SOCKS system proxy hands it through Env.
func EnvWith ¶ added in v0.1.418
EnvWith is Env for a CLI run on one provider's behalf, whose own proxy is choice (see With): "" is Env's.
func ForBun ¶ added in v0.1.584
ForBun is a proxy's address as the plugin host's Bun can use it: a SOCKS5 one is bridged, any other is as it is.
func Func ¶
Func is an http.Transport Proxy function: the proxy the request's context names (With), or else the global one, which a host on the user's own network goes around (onLAN).
func Held ¶ added in v0.1.1169
Held is the error ctx holds its requests with (Hold), nil when it holds none.
func Hold ¶ added in v0.1.1169
Hold is ctx for work magpie was not asked to do and must not send: no request made with it through Func, or a transport Dispatch made, leaves the machine; each fails with err before it dials (#1518, allowance reads while the user has them read only when asked).
func Install ¶
func Install()
Install routes http.DefaultTransport (and so http.DefaultClient) through Func, and http.DefaultClient's requests made on a provider's behalf (With) through a transport of that provider's proxy (Dispatch).
func Redact ¶ added in v0.1.1222
Redact is a proxy address as magpie may show it: in a log line, an error, a status or the GUI (#852, #1886). Its user and password are left out, and the rest kept as it was written (no scheme added to one written without). A malformed address is "", because its userinfo cannot be safely separated. Requests still go through the address itself; only what is shown of it goes through here.
func With ¶ added in v0.1.418
With is ctx for requests made on behalf of one provider, whose own proxy is choice (issue #237: Codex through a proxy, a vendor at home without): "" follows the global one, "direct" goes through none, anything else is the proxy's address (http://, https://, socks5://; host:port means http). Requests made with it through Func, or through a transport Dispatch made, take that proxy. A choice ctx already names is replaced, "" too: a request magpie makes for one provider while serving another's (a web search asked of Codex in a turn served by a provider set to "direct", #1522) goes through its own provider's proxy, never the one it was made under. A provider's leave not to check its certificate (WithUncheckedTLS) goes the same way: it is the outer provider's, and dropped here.
func WithUncheckedTLS ¶ added in v0.1.1258
WithUncheckedTLS is ctx for requests made on behalf of a provider the user added whose HTTPS server they asked magpie not to check the certificate of (#2383, fangzhengjin: vLLM on the LAN, Ollama behind a self-signed cert, a company CA): a request through a transport Dispatch made to the host of one of bases, over https, has its certificate taken as it is, through a transport kept for that host alone. Any other host — a redirect elsewhere, an image or a balance URL on another host — is checked as before, and an https:// proxy is refused for it (uncheckTLS). With (a request made for another provider) drops it.