netproxy

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package netproxy sends Go's HTTP requests through the proxy the user set in the system's settings, as browsers and the app's web pages do, with its bypass list and automatic configuration (PAC files, WPAD):

client := &http.Client{Transport: netproxy.Transport()}

Golet's own requests go this way: the updater's, and those of the fetch and websocket plugins unless their options name a client.

Proxy decides, for each request:

  1. Loopback hosts (localhost, *.localhost, 127.0.0.0/8, ::1) are reached directly.
  2. When any of HTTP_PROXY, HTTPS_PROXY, ALL_PROXY or NO_PROXY (or its lowercase name) is set, the environment decides, as http.ProxyFromEnvironment does: an explicit setting wins over the system's.
  3. Otherwise the system's settings for the URL do: WinHTTP's reading of the user's settings on Windows, with automatic detection and PAC files; CFNetwork's on macOS, with PAC files; GIO's default proxy resolver on Linux, which reads GNOME's settings, or KDE's and PAC files through libproxy. Where none answers, requests go direct.

The system's answer for a scheme and host is kept for 5 seconds, so a change of the settings applies to the requests that follow without restarting the app. Requests under way keep their connections, and Go's transport keys idle connections by their proxy, so none opened through the previous proxy is reused for the new one.

Go's transport speaks to HTTP and HTTPS proxies and to SOCKS5: a SOCKS proxy of unknown version is taken for SOCKS5, and SOCKS4 proxies are skipped. A proxy's password is sent only when the system's answer holds it, as GNOME's settings can. In browsers (js/wasm) the browser makes the requests, with its own proxy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Proxy

func Proxy(req *http.Request) (*url.URL, error)

Proxy returns the proxy for req, or nil to connect directly. It is an http.Transport's Proxy, safe from any goroutine; it may block while the system runs a PAC file.

func Transport

func Transport() *http.Transport

Transport returns a transport like http.DefaultTransport whose Proxy is Proxy. It is shared: clone it to change its settings.

Types

This section is empty.

Jump to

Keyboard shortcuts

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