httpproxy

package module
Version: v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2021 License: MIT Imports: 14 Imported by: 3

README

http proxy

HTTP proxy handler and dialer

Build Go Report Card GoDoc GitHub license gocover.io

This project is to add protocol support for the Bridge, or it can be used alone

The following is the implementation of other proxy protocols

Usage

API Documentation

Example

License

Licensed under the MIT License. See LICENSE for the full license text.

Documentation

Index

Constants

View Source
const (
	BasicAuthName         = "Basic"
	ProxyAuthorizationKey = "Proxy-Authorization"
	ProxyAuthenticateKey  = "Proxy-Authenticate"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Authentication

type Authentication interface {
	Auth(http.ResponseWriter, *http.Request) bool
}

Authentication proxy authentication

func BasicAuth

func BasicAuth(username, password string) Authentication

BasicAuth HTTP Basic authentication for Header Proxy-Authorization

func BasicAuthFunc

func BasicAuthFunc(f func(username, password string) bool) Authentication

BasicAuthFunc HTTP Basic authentication for Header Proxy-Authorization

type AuthenticationFunc

type AuthenticationFunc func(http.ResponseWriter, *http.Request) bool

AuthenticationFunc Authentication interface is implemented

func (AuthenticationFunc) Auth

Auth authentication processing

type BytesPool added in v0.3.2

type BytesPool interface {
	Get() []byte
	Put([]byte)
}

BytesPool is an interface for getting and returning temporary bytes for use by io.CopyBuffer.

type Dialer

type Dialer struct {
	// ProxyDial specifies the optional dial function for
	// establishing the transport connection.
	ProxyDial func(context.Context, string, string) (net.Conn, error)

	// TLSClientConfig specifies the TLS configuration to use with
	// tls.Client.
	// If nil, the TLS is not used.
	// If non-nil, HTTP/2 support may not be enabled by default.
	TLSClientConfig *tls.Config

	// ProxyHeader optionally specifies headers to send to
	// proxies during CONNECT requests.
	ProxyHeader http.Header

	// Proxy proxy server address
	Proxy string

	// Userinfo use userinfo authentication if not empty
	Userinfo *url.Userinfo

	// Timeout is the maximum amount of time a dial will wait for
	// a connect to complete. The default is no timeout
	Timeout time.Duration
}

Dialer holds HTTP CONNECT options.

func NewDialer

func NewDialer(addr string) (*Dialer, error)

NewDialer is create a new HTTP CONNECT connection

func (*Dialer) Dial

func (d *Dialer) Dial(network string, address string) (net.Conn, error)

Dial connects to the provided address on the provided network.

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext connects to the provided address on the provided network.

type Logger added in v0.4.0

type Logger interface {
	Println(v ...interface{})
}

type ProxyHandler

type ProxyHandler struct {
	// Client  is used without the connect method
	Client *http.Client
	// ProxyDial specifies the optional proxyDial function for
	// establishing the transport connection.
	ProxyDial func(context.Context, string, string) (net.Conn, error)
	// Authentication is proxy authentication
	Authentication Authentication
	// NotFound Not proxy requests
	NotFound http.Handler
	// Logger error log
	Logger Logger
	// BytesPool getting and returning temporary bytes for use by io.CopyBuffer
	BytesPool BytesPool
}

ProxyHandler proxy handler

func (*ProxyHandler) ServeHTTP

func (p *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type SimpleServer added in v0.3.3

type SimpleServer struct {
	ProxyHandler
	Server   http.Server
	Listener net.Listener
	Network  string
	Address  string
	Username string
	Password string
}

SimpleServer is a simplified server, which can be configured as easily as client.

func NewSimpleServer added in v0.3.3

func NewSimpleServer(addr string) (*SimpleServer, error)

NewServer creates a new NewSimpleServer

func (*SimpleServer) Close added in v0.3.3

func (s *SimpleServer) Close() error

Close closes the listener

func (*SimpleServer) ProxyURL added in v0.3.3

func (s *SimpleServer) ProxyURL() string

ProxyURL returns the URL of the proxy

func (*SimpleServer) Run added in v0.3.3

func (s *SimpleServer) Run(ctx context.Context) error

Run the server

func (*SimpleServer) Start added in v0.3.3

func (s *SimpleServer) Start(ctx context.Context) error

Start the server

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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