proxy

package
v0.0.0-...-ba9f62b Latest Latest
Warning

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

Go to latest
Published: May 3, 2016 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HTTP Methods
	GET  = iota
	POST = iota
)

Variables

View Source
var (
	// defaults
	DefaultBlacklist = NewBlacklist()

	// errors
	HostnameBlacklisted      = errors.New("This hostname has been blacklisted.")
	SourceAddressBlacklisted = errors.New("This source address has been blacklisted.")
)
View Source
var (
	// defaults
	DefaultHttpClient = retryablehttp.NewClient()

	// errors
	UnknownMethodError = errors.New("Unknown method for proxy request")
)
View Source
var (
	DefaultBlacklistJSONFile = "./proxy/blacklist.json"
)

Functions

This section is empty.

Types

type Blacklist

type Blacklist interface {
	IsBlacklisted(req Request) *error
}

Blacklist is a type which handles marking if a `Request` should not be processed. This most often happens based on hostname or source ip.

See `DefaultBacklist` for a shared instance

func NewBlacklist

func NewBlacklist() Blacklist

func NewEmptyBlacklist

func NewEmptyBlacklist() Blacklist

NewEmptyBlacklist returns an empty instance of EmptyBlacklist

func NewJSONBlacklist

func NewJSONBlacklist() (Blacklist, error)

NewJSONBlacklist returns a defaulted instance of the `blacklist.json` file parsed.

func NewJSONBlacklistFromFile

func NewJSONBlacklistFromFile(file string) (Blacklist, error)

NewJSONBlacklistFromFile reads the given file and returns a `JSONBlacklist` instance.

type EmptyBlacklist

type EmptyBlacklist struct {
	Blacklist
}

EmptyBlacklist allows all requests through. This isn't recommended for most deployments because it offers no prevention of clients or requests.

However, right now it is used when there is an error loading another blacklist.

func (EmptyBlacklist) IsBlacklisted

func (b EmptyBlacklist) IsBlacklisted(req Request) *error

type HTMLTransformer

type HTMLTransformer struct {
	Transformer
}

func (HTMLTransformer) Transform

func (t HTMLTransformer) Transform(orig_url url.URL, in Response) Response

type JSONBlacklist

type JSONBlacklist struct {
	Blacklist
	// contains filtered or unexported fields
}

JSONBlacklist represents a blacklist that's read from a JSON blob from the local filesystem.

func (JSONBlacklist) IsBlacklisted

func (b JSONBlacklist) IsBlacklisted(req Request) *error

type JSONBlacklistData

type JSONBlacklistData struct {
	Hostnames []string `json:"hostnames"`
	SourceIPs []string `json:"sourceIPs"`
}

JSONBlacklistData contains the json structure of the blacklist file to read and return inside the JSONBlacklist.

type Proxy

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

A Proxy is a shared interface for making requests it is supposed to be shared across goroutines and also will perform changes to the request and response in accordance to this proxy's requirements (headers, response parsing / transforms, etc).

Usage

var DefaultProxy := NewProxy()

res, err := DefaultProxy.Get("http://example.com")

func NewProxy

func NewProxy() Proxy

NewProxy() creates a new instance of the proxy to be shared across goroutines

func (Proxy) Get

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

type Request

type Request struct {
	URL           url.URL
	Method        int
	SourceAddress net.IP
	// contains filtered or unexported fields
}

Request holds onto the information from the requestor to make the request on their behalf. Often we want to bring in as little information as possible from them.

There are a few options along the request to be included for metrics and performance monitoring.

type Response

type Response struct {
	Reader      io.Reader
	ContentType string
}

Response contains a buffered output of the interaction performed on behalf of the requestor.

type Transformer

type Transformer interface {
	Transform(url.URL, Response) Response
}

Transformer is a type which performs some action on a `Response` and returns another `Response`.

Typical use cases are for doing things with html or metrics.

func NewHTMLTransformer

func NewHTMLTransformer() Transformer

Jump to

Keyboard shortcuts

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