ieproxy

package module
v0.0.0-...-199f1f8 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2017 License: MIT Imports: 3 Imported by: 0

README

ieproxy

Go package to detect the proxy settings on Windows platform.

The settings are read from the registry (CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings).

You can either get the settings via GetConf or set the environment variables via OverrideEnvWithStaticProxy.

If you want to use it system wide, you should use an init function:

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

For more informations, take a look at the documentation

Documentation

Overview

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
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: ...
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

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 AutomaticProxyConf

type AutomaticProxyConf struct {
	// Is the proxy active?
	Active bool
	// URL of the .pac file
	URL string
}

AutomaticProxyConf contains the configuration for automatic proxy

func (*AutomaticProxyConf) FindProxyForURL

func (apc *AutomaticProxyConf) FindProxyForURL(URL string) string

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

type ProxyConf

type ProxyConf struct {
	Static    StaticProxyConf    // static configuration
	Automatic AutomaticProxyConf // automatic configuration
}

ProxyConf gathers the configuration for proxy

func GetConf

func GetConf() ProxyConf

GetConf retrieves the proxy configuration from the Windows Regedit

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

Jump to

Keyboard shortcuts

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