pac

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package pac provides a PAC file parser and evaluator. Under the hood uses Goja JavaScript VM to run the PAC script. It supports Mozilla FindProxyForURL and the Microsoft IPv6 extension FindProxyForURLEx as well as all the helper functions as described in the PAC specification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SupportedFunctions

func SupportedFunctions() []string

SupportedFunctions returns a list of supported javascript functions from the PAC specification.

Types

type Mode

type Mode int

Mode is a proxy mode.

const (
	DIRECT Mode = iota
	PROXY
	HTTP
	HTTPS
	SOCKS
	SOCKS4
	SOCKS5
)

func (Mode) String

func (i Mode) String() string

type Option

type Option func(vm *goja.Runtime)

Option allows to set additional options before evaluating the PAC script.

type Proxies

type Proxies string

Proxies is a list of proxies as returned from FindProxyForURL. If the string is empty, no proxies should be used. The string can contain any number of the following building blocks, separated by a semicolon: <type> <host>:<port> where <type> = "DIRECT" | "PROXY" | "SOCKS" | "HTTP" | "HTTPS" | "SOCKS4" <host> = a valid DNS hostname or IP address <port> = a valid port number.

See https://developer.mozilla.org/en-US/docs/Web/HTTP/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_PAC_file#return_value_format

func (Proxies) All

func (s Proxies) All() ([]Proxy, error)

func (Proxies) First

func (s Proxies) First() (Proxy, error)

func (Proxies) String

func (s Proxies) String() string

type Proxy

type Proxy struct {
	Mode Mode
	Host string
	Port string
}

Proxy specifies proxy to be used as parsed from FindProxyForURL result. See ParseResult for details.

func (Proxy) URL

func (p Proxy) URL() *url.URL

URL returns proxy URL as used in http.Transport.Proxy() (it returns nil if proxy is DIRECT).

type ProxyResolver

type ProxyResolver struct {
	// contains filtered or unexported fields
}

ProxyResolver is a PAC resolver. It can be used to resolve a proxy for a given URL. It supports both FindProxyForURL and FindProxyForURLEx functions. It is not safe for concurrent use.

func NewProxyResolver

func NewProxyResolver(cfg *ProxyResolverConfig, r *net.Resolver, opts ...Option) (*ProxyResolver, error)

func (*ProxyResolver) FindProxyForURL

func (pr *ProxyResolver) FindProxyForURL(u *url.URL, hostname string) (string, error)

FindProxyForURL calls FindProxyForURL or FindProxyForURLEx function in the PAC script. The hostname is optional, if empty it will be extracted from URL.

type ProxyResolverConfig

type ProxyResolverConfig struct {
	Script    string
	AlertSink io.Writer
	// contains filtered or unexported fields
}

func (*ProxyResolverConfig) Validate

func (c *ProxyResolverConfig) Validate() error

type ProxyResolverPool

type ProxyResolverPool struct {
	// contains filtered or unexported fields
}

func NewProxyResolverPool

func NewProxyResolverPool(cfg *ProxyResolverConfig, r *net.Resolver, opts ...Option) (*ProxyResolverPool, error)

func (*ProxyResolverPool) FindProxyForURL

func (pool *ProxyResolverPool) FindProxyForURL(u *url.URL, hostname string) (p string, err error)

FindProxyForURL calls FindProxyForURL or FindProxyForURLEx function in the PAC script with the alternate hostname. The hostname is optional, if empty it will be extracted from URL. This is to handle cases when the hostname is not a valid hostname, but a URL.

Jump to

Keyboard shortcuts

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