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

Code:

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

Package Files

GetProxyFunc.go ieproxy.go ieproxy_unix.go pac_unix.go proxyMiddleman_unix.go utils.go

func GetProxyFunc Uses

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

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

func OverrideEnvWithStaticProxy Uses

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 Uses

func StringFromUTF16Ptr(s *uint16) string

StringFromUTF16Ptr converts a *uint16 C string to a Go String

type ProxyConf Uses

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

ProxyConf gathers the configuration for proxy

func GetConf Uses

func GetConf() ProxyConf

GetConf retrieves the proxy configuration from the Windows Regedit

type ProxyScriptConf Uses

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 Uses

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

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

type StaticProxyConf Uses

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

Directories

PathSynopsis
autoloadPackage autoload automatically calls OverrideEnvWithStaticProxy, which writes new values to the `http_proxy`, `https_proxy` and `no_proxy` environment variables.

Package ieproxy imports 5 packages (graph) and is imported by 4 packages. Updated 2019-08-06. Refresh now. Tools for package owners.