go-ieproxy – github.com/mattn/go-ieproxy Index | Examples | Files | Directories

package ieproxy

import "github.com/mattn/go-ieproxy"

Package ieproxy is a utility to retrieve the proxy parameters (especially of Internet Explorer on windows)

On windows, it gathers the parameters from the registry (regedit), while it uses env variable on other platforms

Example

Code:play 

package main

import (
	"fmt"
	"net/http"
	"os"
)

func init() {
	OverrideEnvWithStaticProxy()
	http.DefaultTransport.(*http.Transport).Proxy = http.ProxyFromEnvironment
}

func main() {
	fmt.Println("== Proxy configuration ==")
	for _, name := range []string{"http_proxy", "https_proxy", "no_proxy"} {
		fmt.Println(name + ": " + os.Getenv(name))
	}

	fmt.Println("== Proxy test ==")

	req, err := http.NewRequest("GET", "https://golang.org/", nil)
	if err != nil {
		panic(err)
	}
	url, err := http.DefaultTransport.(*http.Transport).Proxy(req)
	if err != nil {
		panic(err)
	}
	if url != nil {
		fmt.Println("PROXY " + url.String())
	} else {
		fmt.Println("DIRECT")
	}
	// Coming output: == Proxy configuration ==
	// http_proxy: ...
}

Index

Examples

Functions

func GetProxyFunc

func GetProxyFunc() func(*http.Request) (*url.URL, error)

GetProxyFunc is a forwarder for the OS-Exclusive proxyMiddleman_os.go files

func OverrideEnvWithStaticProxy

func OverrideEnvWithStaticProxy()

OverrideEnvWithStaticProxy writes new values to the `http_proxy`, `https_proxy` and `no_proxy` environment variables. The values are taken from the Windows Regedit (should be called in `init()` function - see example)

func StringFromUTF16Ptr

func StringFromUTF16Ptr(s *uint16) string

StringFromUTF16Ptr converts a *uint16 C string to a Go String

Types

type ProxyConf

type ProxyConf struct {
	Static    StaticProxyConf // static configuration
	Automatic ProxyScriptConf // script configuration
}

ProxyConf gathers the configuration for proxy

func GetConf

func GetConf() ProxyConf

GetConf retrieves the proxy configuration from the Windows Regedit

func ReloadConf

func ReloadConf() ProxyConf

ReloadConf reloads the proxy configuration

type ProxyScriptConf

type ProxyScriptConf struct {
	// Is the proxy active?
	Active bool
	// PreConfiguredURL of the .pac file.
	// If this is empty and Active is true, auto-configuration should be assumed.
	PreConfiguredURL string
}

ProxyScriptConf contains the configuration for automatic proxy

func (*ProxyScriptConf) FindProxyForURL

func (psc *ProxyScriptConf) FindProxyForURL(URL string) string

FindProxyForURL computes the proxy for a given URL according to the pac file

type StaticProxyConf

type StaticProxyConf struct {
	// Is the proxy active?
	Active bool
	// Proxy address for each scheme (http, https)
	// "" (empty string) is the fallback proxy
	Protocols map[string]string
	// Addresses not to be browsed via the proxy (comma-separated, linux-like)
	NoProxy string
}

StaticProxyConf contains the configuration for static proxy

Source Files

ieproxy.go ieproxy_unix.go pac_unix.go proxy_middleman.go proxy_middleman_unix.go utils.go

Directories

PathSynopsis
autoloadPackage autoload automatically calls OverrideEnvWithStaticProxy, which writes new values to the `http_proxy`, `https_proxy` and `no_proxy` environment variables.
Version
v0.0.12 (latest)
Published
May 22, 2024
Platform
js/wasm
Imports
5 packages
Last checked
now

Tools for package owners.