Help us shape the future of Go! Take the 2026 Go Developer Survey

sysproxy

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package sysproxy chooses the proxy an outbound HTTP request goes through the way .NET, and so PowerShell, chooses it on the same host (ADR-0464).

Why

Go's default transport reads only the HTTPS_PROXY family of variables. A Windows server is usually configured the other way: a PAC script or a proxy in Internet Options, set by group policy, and no variable at all. There every PowerShell a Worker starts finds the proxy and every Go Worker goes direct — into a firewall that drops the packets, so the request fails on a timeout rather than with a message. One host then has two network paths, and which one a task takes depends on the language its Worker is written in.

The choice, made once at startup

  1. ATLAS_SYSTEM_PROXY=off keeps Go's own behaviour: the variables, nothing else.
  2. A proxy variable (HTTPS_PROXY, HTTP_PROXY, either case) wins, as it does in .NET, and Go's transport reads it as it always has.
  3. Otherwise, on Windows, the account's proxy settings as WinHTTP reports them: a PAC URL, automatic detection (WPAD), a manual proxy and its bypass list. That is what .NET's HttpWindowsProxy reads, and the rules below are its rules.
  4. Anywhere else, or with no settings, nothing changes.

The rules for one request

Loopback and the host's own addresses never go through a proxy, whatever a PAC script says: a supervised Worker reaches its own server over 127.0.0.1, or over the address the server listens on. Auto-configuration, when set, is asked first and its answer is final, DIRECT included; when it cannot answer, the manual proxy applies with its bypass list; with neither, the request goes direct. Auto-detection that found nothing is not tried again for two minutes, because WPAD discovery can take seconds. An answer is believed for five minutes per scheme, host and port; a fallback after a failure for thirty seconds, so a passing PAC outage does not pin a host to the wrong route. Only the first proxy of a list is used: Go's transport takes one per request, where .NET fails over along the list.

Index

Constants

View Source
const EnvSwitch = "ATLAS_SYSTEM_PROXY"

EnvSwitch turns the Windows settings off: off, false, 0 or no keeps Go's default.

Variables

This section is empty.

Functions

func Install

func Install(getenv func(string) string) (Mode, Settings)

Install points http.DefaultTransport's proxy at the choice described in the package documentation, and reports which it made and the settings it follows. Call it once at startup, before anything clones the default transport.

Types

type Mode

type Mode string

Mode says where this process takes its outbound proxy from.

const (
	// ModeEnvironment: a proxy variable is set, and Go's transport reads it.
	ModeEnvironment Mode = "environment"
	// ModeWindows: the Windows proxy settings, read the way .NET reads them.
	ModeWindows Mode = "windows"
	// ModeOff: ATLAS_SYSTEM_PROXY switched the Windows settings off.
	ModeOff Mode = "off"
	// ModeNone: no system settings to follow — not Windows, or none configured.
	ModeNone Mode = "none"
)

type Settings

type Settings struct {
	AutoDetect    bool
	AutoConfigURL string
	Proxy         string
	Bypass        string
}

Settings are an account's proxy settings as WinHTTP reports them: the Internet Options an administrator or a group policy set.

func (Settings) Redacted

func (s Settings) Redacted() Settings

Redacted is s with any credentials in its addresses masked, for a log line.

Jump to

Keyboard shortcuts

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