netproxy

package
v0.1.1259 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 16 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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.

View Source
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

func Bridge(socks *url.URL) (string, error)

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

func Choice(ctx context.Context) string

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

func DialSOCKS(ctx context.Context, socks *url.URL, addr string) (net.Conn, error)

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

func Env(env []string) []string

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

func EnvForBun(env []string) []string

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

func EnvWith(choice string, env []string) []string

EnvWith is Env for a CLI run on one provider's behalf, whose own proxy is choice (see With): "" is Env's.

func For

func For(u *url.URL) (*url.URL, error)

For is the proxy a request to u goes through; nil means direct.

func ForBun added in v0.1.584

func ForBun(proxy string) string

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 Func(req *http.Request) (*url.URL, error)

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

func Held(ctx context.Context) error

Held is the error ctx holds its requests with (Hold), nil when it holds none.

func Hold added in v0.1.1169

func Hold(ctx context.Context, err error) context.Context

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 IsSOCKS added in v0.1.584

func IsSOCKS(u *url.URL) bool

IsSOCKS is whether the proxy's address is a SOCKS5 one.

func Parse

func Parse(s string) (*url.URL, error)

Parse reads a proxy address; a bare host:port is an HTTP proxy.

func Redact added in v0.1.1222

func Redact(raw string) string

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

func With(ctx context.Context, choice string) context.Context

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

func WithUncheckedTLS(ctx context.Context, bases ...string) context.Context

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.

Types

type Proxy

type Proxy struct {
	URL    string
	HTTP   string
	SOCKS  string
	Bypass []string
}

Proxy is the system's proxy: one address, and the hosts that skip it. HTTP and SOCKS are the system's entries for plain http:// requests and for SOCKS, each alone, for a client that reads them so (Codex's reqwest takes macOS' HTTP entry and nothing else for an http:// URL).

func System

func System() Proxy

System reads the system proxy, at most every 15 seconds while one is set and every 2 while none is.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL