httpproxyfailover

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2020 License: MIT Imports: 12 Imported by: 0

README

httpproxyfailover

A proxy server for HTTP proxies that picks out one of available HTTP proxies.

Installation

As a command
go get github.com/ichiban/httpproxyfailover/cmd/httpproxyfailover
As a library
go get github.com/ichiban/httpproxyfailover

Usage

Let's say we have 2 HTTP proxies running, namely http://localhost:8081 and http://localhost:8082. We use the first one mainly but in case that the first one is down, we want to use the second one.

$ curl -D- -p -x http://localhost:8081 https://httpbin.org/status/200
HTTP/1.1 502 Bad Gateway
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Sun, 13 Sep 2020 05:46:00 GMT
Content-Length: 1

curl: (56) Received HTTP code 502 from proxy after CONNECT
$ curl -D- -p -x http://localhost:8082 https://httpbin.org/status/200
HTTP/1.1 200 OK
Content-Length: 0
Date: Sun, 13 Sep 2020 05:46:36 GMT

HTTP/2 200 
date: Sun, 13 Sep 2020 05:46:36 GMT
content-type: text/html; charset=utf-8
content-length: 0
server: gunicorn/19.9.0
access-control-allow-origin: *
access-control-allow-credentials: true

By using httpproxyfailover, the trial and error shown above can be done automatically.

$ httpproxyfailover -p 8080 http://localhost:8081 http://localhost:8082
$ curl -D- -p -x http://localhost:8080 https://httpbin.org/status/200
HTTP/1.1 200 OK
Date: Sun, 13 Sep 2020 06:01:39 GMT
Content-Length: 0

HTTP/2 200 
date: Sun, 13 Sep 2020 06:01:40 GMT
content-type: text/html; charset=utf-8
content-length: 0
server: gunicorn/19.9.0
access-control-allow-origin: *
access-control-allow-credentials: true

License

Distributed under the MIT license. See LICENSE for more information.

Contributing

  1. Fork it (https://github.com/ichiban/httpproxyfailover/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Proxy

type Proxy struct {
	// Backends hold backend HTTP proxies. The Proxy tries backend HTTP proxies in order of the slice and use the first one that responds with a successful status code (2XX).
	Backends []string

	// Timeout sets the deadline of trial of each backend HTTP proxy if provided.
	Timeout time.Duration

	// Callback is signaled after every trial of the backend HTTP proxies if provided.
	// The first argument is the CONNECT request, the second argument is the backend HTTP proxy in trial, and the last argument is the resulting error which is nil if it succeeded.
	Callback func(*http.Request, string, error)
}

Proxy is a proxy for backend HTTP proxies.

func (Proxy) ServeHTTP

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

type UnsuccessfulStatusError

type UnsuccessfulStatusError struct {
	StatusCode int
	Status     string
}

func (*UnsuccessfulStatusError) Error

func (err *UnsuccessfulStatusError) Error() string

Directories

Path Synopsis
cmd
testproxy command

Jump to

Keyboard shortcuts

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