pac2http

package module
v0.0.0-...-0e60f35 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2020 License: MIT Imports: 13 Imported by: 0

README

Pac2HTTP

Pac2HTTP is a package for exposing proxy auto-config (PAC) files as a simple HTTP proxy, so that applications without PAC support can utilise PAC's flexibility.

Installation

go get github.com/ssz66666/pac2http

Example

package main

import (
	"log"
	"net/http"

	"github.com/ssz66666/pac2http"
)

func main() {
	listening := ":8080"
	svr, err := pac2http.NewPacProxyHTTPServerWithURL(
		"https://raw.githubusercontent.com/petronny/gfwlist2pac/master/gfwlist.pac",
	)
    if err != nil {
        log.Fatal(err)
    }
	log.Printf("Listening on %s\n", listening)
	log.Fatal(http.ListenAndServe(listening, svr))
}

Documentation

Overview

Package pac2http provides a convenient interface to build a http proxy from a proxy auto config file

Index

Constants

This section is empty.

Variables

View Source
var DirectDialer = &net.Dialer{
	Timeout:   30 * time.Second,
	KeepAlive: 30 * time.Second,
	DualStack: true,
}

DirectDialer is the net.Dialer used for direct connection and forwarding to proxy servers

Functions

func ProxyStringFromPac

func ProxyStringFromPac(findProxyForURL func(string, string) (string, error)) func(string) (string, error)

ProxyStringFromPac takes a thread-safe FindProxyForURL(url string, hostname string) (string, error) function, returns a func(string) (string, error), which return "DIRECT" for DIRECT or string url for proxy.

func TransportProxyFromPac

func TransportProxyFromPac(findProxyForURL func(string, string) (string, error)) func(*url.URL) (*url.URL, error)

TransportProxyFromPac takes a thread-safe FindProxyForURL(url string, hostname string) (string, error) function, returns a func(*url.URL) (*url.URL, error), which return nil for DIRECT or *url.URL for proxy.

Types

type PacProxyDialer

type PacProxyDialer struct {
	ProxyFunc  func(string) (string, error)
	DialerMap  cache.LoadingCache //[string]Dialer, "DIRECT" or a URL string
	ProxyCache cache.LoadingCache // [string]Dialer
}

PacProxyDialer implements net.Dialer interface which uses pac file to determine the underlying Dialer to use

func NewPacProxyDialer

func NewPacProxyDialer(proxyFunc func(string) (string, error), cacheOptions ...cache.Option) *PacProxyDialer

NewPacProxyDialer creates an instance of PacProxyDialer with given proxy function

func (*PacProxyDialer) Dial

func (p *PacProxyDialer) Dial(network string, hostname string) (net.Conn, error)

Dial works like net.Dialer.Dial for a PacProxyDialer

func (*PacProxyDialer) DialContext

func (p *PacProxyDialer) DialContext(ctx context.Context, network string, hostname string) (net.Conn, error)

DialContext works like net.Dialer.DialContext for a PacProxyDialer

type PacProxyHTTPServer

type PacProxyHTTPServer struct {
	Proxy     *goproxy.ProxyHttpServer
	PacParser *gopac.Parser
	// contains filtered or unexported fields
}

PacProxyHTTPServer implements http.Handler interface which acts as a http proxy and serve traffic using the pac file

func NewPacProxyHTTPServer

func NewPacProxyHTTPServer(parser *gopac.Parser) *PacProxyHTTPServer

NewPacProxyHTTPServer creates an instance of PacProxyHTTPServer with the given initialised gopac.Parser.

func NewPacProxyHTTPServerWithPath

func NewPacProxyHTTPServerWithPath(path string) (*PacProxyHTTPServer, error)

NewPacProxyHTTPServerWithPath is a convenience function to create an instance of PacProxyHTTPServer with a local PAC file.

func NewPacProxyHTTPServerWithURL

func NewPacProxyHTTPServerWithURL(url string) (*PacProxyHTTPServer, error)

NewPacProxyHTTPServerWithURL is a convenience function to create an instance of PacProxyHTTPServer with a remote PAC URL.

func (*PacProxyHTTPServer) GetProxy

func (svr *PacProxyHTTPServer) GetProxy() func(*http.Request) (*url.URL, error)

GetProxy converts the pac to a proxy function usable for Transport.Proxy

func (*PacProxyHTTPServer) GetProxyFunc

func (svr *PacProxyHTTPServer) GetProxyFunc() func(string) (string, error)

GetProxyFunc converts the pac to a proxy function, used by PacProxyDialer to give a net.Dialer.Dial function

func (*PacProxyHTTPServer) ServeHTTP

func (svr *PacProxyHTTPServer) ServeHTTP(w http.ResponseWriter, req *http.Request)

type StringOrError

type StringOrError struct {
	String string
	Err    error
}

StringOrError represents either a string or error

func PacEntryToProxyString

func PacEntryToProxyString(entry string) []*StringOrError

PacEntryToProxyString converts a pac entry string to a *StringOrError array containing "DIRECT", or a proxy url string, or an error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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