proxyfilters

package
v0.0.3-0...-4b7b66f Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddForwardedFor = filters.FilterFunc(func(cs *filters.ConnectionState, req *http.Request, next filters.Next) (*http.Response, *filters.ConnectionState, error) {
	if req.Method != http.MethodConnect {
		if clientIP, _, err := net.SplitHostPort(req.RemoteAddr); err == nil {
			if prior, ok := req.Header[xForwardedFor]; ok {
				clientIP = strings.Join(prior, ", ") + ", " + clientIP
			}
			req.Header.Set(xForwardedFor, clientIP)
		}
	}
	return next(cs, req)
})

AddForwardedFor adds an X-Forwarded-For header based on the request's RemoteAddr.

View Source
var DiscardInitialPersistentRequest = filters.FilterFunc(func(cs *filters.ConnectionState, req *http.Request, next filters.Next) (*http.Response, *filters.ConnectionState, error) {
	isInitialPersistent, _ := strconv.ParseBool(req.Header.Get(xLanternPersistent))
	if isInitialPersistent {
		return filters.Discard(cs, req)
	}
	return next(cs, req)
})

DiscardInitialPersistentRequest discards the initial request for persistent HTTP connections from the Lantern client.

View Source
var RecordOp = filters.FilterFunc(func(cs *filters.ConnectionState, req *http.Request, next filters.Next) (*http.Response, *filters.ConnectionState, error) {
	name := "proxy_http"
	if req.Method == http.MethodConnect {
		name += "s"
	}
	op := ops.Begin(name)
	resp, nextCtx, err := next(cs, req)
	if err != nil {
		op.FailIf(err)
		logFilterError(err)
	}
	op.End()
	return resp, nextCtx, err
})

RecordOp records the proxy_http op.

Functions

func BlockLocal

func BlockLocal(exceptions []string) filters.Filter

BlockLocal blocks attempted accesses to localhost unless they're one of the listed exceptions.

func RateLimit

func RateLimit(numClients int, hostPeriods map[string]time.Duration) filters.Filter

RateLimit restricts access to only specific hosts and limits the rate at which clients (identified by IP address) are allowed to access thoses hosts.

func RestrictConnectPorts

func RestrictConnectPorts(allowedPorts []int) filters.Filter

RestrictConnectPorts restricts CONNECT requests to the given list of allowed ports and returns either a 400 error if the request is missing a port or a 403 error if the port is not allowed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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