connect

package module
v0.0.0-...-6db2dfc Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: Unlicense Imports: 15 Imported by: 0

README

connect GoDoc Go Report Card

This package distributes requests through a pool of proxies, acting as a proxy gateway that supports CONNECT requests. Proxy rotation spreads out usage as much as possible to avoid IP bans or restrictions. The gateway only accepts proxy urls with the https scheme.

Installation

go get -u github.com/aidenesco/connect

Usage

Loading proxies

import "github.com/aidenesco/connect"

func main() {
    pool := connect.NewPool()

    proxyUrl, _ := url.Parse("https://username:password@host:port")

    _ = pool.AddProxy(proxyUrl)

Server

import "github.com/aidenesco/connect"

func main() {
    pool := connect.NewPool()
    //Load pool with your proxies

    server := &http.Server{
        Addr:         ":443",
        Handler:      http.HandlerFunc(pool.Serve),
        TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler)),
    }

    log.Fatal(server.ListenAndServeTLS("your-cert", "your-key"))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

Pool holds a ring of proxies used to distribute requests

func NewPool

func NewPool() *Pool

NewPool returns a new, empty pool

func (*Pool) AddProxy

func (p *Pool) AddProxy(proxy *Proxy)

AddProxy adds a Proxy to the pool

func (*Pool) Proxy

func (p *Pool) Proxy(r *http.Request) (*url.URL, error)

Proxy is used to distribute client side requests when using an http.Client

func (*Pool) Serve

func (p *Pool) Serve(w http.ResponseWriter, r *http.Request)

Serve is an http handler to serve as a gateway proxy. Only accepts CONNECT requests

type Proxy

type Proxy struct {
	URL *url.URL
	// contains filtered or unexported fields
}

func NewProxy

func NewProxy(u *url.URL, o ...ProxyOption) (p *Proxy, err error)

func (*Proxy) Connection

func (p *Proxy) Connection(to *url.URL) (conn net.Conn, err error)

type ProxyOption

type ProxyOption func(*Proxy) error

ProxyOption is an option that modifies a proxyContainer

func WithBetweenUse

func WithBetweenUse(dur time.Duration) ProxyOption

WithBetweenUse sets a duration for a proxy to wait before it's used again on the same host

Jump to

Keyboard shortcuts

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