Skip to content

memclutter/gorequests-proxy

Repository files navigation

gorequests-proxy

Proxy middleware for gorequests — route a request through a random HTTP(S) or SOCKS proxy from a list, with one Use() call.

Release Go Reference Go Report Card Go version CI codecov License: MIT

gorequests-proxy is a ClientOverride middleware for gorequests. Give it a list of proxy URLs and it rewires the request's transport to dial through one of them, chosen at random — HTTP and HTTPS proxies via Go's proxy transport, SOCKS proxies via h12.io/socks.

Contents

Install

go get github.com/memclutter/gorequests-proxy

Requires Go 1.18+.

Usage

Pass a Proxy to the Use() method of a request:

import (
	"net/http"

	"github.com/memclutter/gorequests"
	gorequests_proxy "github.com/memclutter/gorequests-proxy"
)

proxy := &gorequests_proxy.Proxy{
	Proxies: []string{
		"http://example.com:5554",
		"http://user:[email protected]:33333",
		"socks5://10.0.0.2:1080",
	},
}

err := gorequests.Get("https://api.ipify.org?format=json").
	Use(proxy).
	ResponseCodeOk(http.StatusOK).
	Exec()

A fresh proxy is picked at random from the list for each Exec().

Options

Field Type Description
Proxies []string Candidate proxy URLs. Entries are trimmed; blank entries are ignored.
AllowEmpty bool When true, an empty list is a no-op (the request runs directly). When false (default), an empty list returns an error.

Proxy URL format

Each entry is a full URL, with optional inline credentials:

http://host:3128
http://user:pass@host:3128
https://host:8443
socks5://host:1080
socks4://host:1080

Any scheme containing socks is dialed through h12.io/socks; everything else is treated as an HTTP(S) proxy.

Composing with retry

gorequests-proxy recognises the transport installed by gorequests-retry, so the two middlewares stack — apply Retry first, then Proxy:

err := gorequests.Get("https://api.example.com/").
	Use(&gorequests_retry.Retry{RetryMax: 3}).
	Use(proxy).
	Exec()

Contributing

Contributions are welcome — see CONTRIBUTING.md for setup, coding conventions, and the commit/PR process. Changes are recorded in CHANGELOG.md.

License

Released under the MIT License.

About

Proxy middleware for gorequests: route requests through HTTP(S) or SOCKS4/5 proxies

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Contributors

Languages