netproxy

package
v0.1.685 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 15 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.

Index

Constants

This section is empty.

Variables

This section is empty.

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

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 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 (ctx is returned as it is), "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.

Types

type Proxy

type Proxy struct {
	URL    string
	Bypass []string
}

Proxy is the system's proxy: one address, and the hosts that skip it.

func System

func System() Proxy

System reads the system proxy, at most every 15 seconds.

Jump to

Keyboard shortcuts

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