proxy

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2022 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MirrorRequest http.RoundTripper = onewayRoundTripper{}

MirrorRequest is a round tripper that can be called to get back the calling request as the core round tripper in a chain.

Functions

func MakeRegexpArray

func MakeRegexpArray(str string) ([]*regexp.Regexp, error)

MakeRegexpArray splits a comma separated list of regexps into an array of Regexp objects.

func MakeRegexpArrayOrDie

func MakeRegexpArrayOrDie(str string) []*regexp.Regexp

MakeRegexpArrayOrDie creates an array of regular expression objects from a string or exits.

func NewProxyHandler

func NewProxyHandler(apiProxyPrefix string, filter *FilterServer, cfg *rest.Config, keepalive time.Duration, appendLocationPath bool) (http.Handler, error)

NewProxyHandler creates an api proxy handler for the cluster

Types

type ErrorResponder

type ErrorResponder interface {
	Error(w http.ResponseWriter, req *http.Request, err error)
}

ErrorResponder abstracts error reporting to the proxy handler to remove the need to hardcode a particular error format.

func NewErrorResponder

func NewErrorResponder(r SimpleErrorResponder) ErrorResponder

type FilterServer

type FilterServer struct {
	// Only paths that match this regexp will be accepted
	AcceptPaths []*regexp.Regexp
	// Paths that match this regexp will be rejected, even if they match the above
	RejectPaths []*regexp.Regexp
	// Hosts are required to match this list of regexp
	AcceptHosts []*regexp.Regexp
	// Methods that match this regexp are rejected
	RejectMethods []*regexp.Regexp
	// contains filtered or unexported fields
}

FilterServer rejects requests which don't match one of the specified regular expressions

func (*FilterServer) HandlerFor

func (f *FilterServer) HandlerFor(delegate http.Handler) *FilterServer

HandlerFor makes a shallow copy of f which passes its requests along to the new delegate.

func (*FilterServer) ServeHTTP

func (f *FilterServer) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type Server

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

Server is a http.Handler which proxies Kubernetes APIs to remote API server.

func NewServer

func NewServer(filebase string, apiProxyPrefix string, staticPrefix string, filter *FilterServer, cfg *rest.Config, keepalive time.Duration, appendLocationPath bool) (*Server, error)

NewServer creates and installs a new Server. 'filter', if non-nil, protects requests to the api only.

func (*Server) Listen

func (s *Server) Listen(address string, port int) (net.Listener, error)

Listen is a simple wrapper around net.Listen.

func (*Server) ServeOnListener

func (s *Server) ServeOnListener(l net.Listener) error

ServeOnListener starts the server using given listener, loops forever.

type SimpleErrorResponder

type SimpleErrorResponder interface {
	Error(err error)
}

SimpleErrorResponder is the legacy implementation of ErrorResponder for callers that only service a single request/response per proxy.

type UpgradeAwareHandler

type UpgradeAwareHandler struct {
	// UpgradeRequired will reject non-upgrade connections if true.
	UpgradeRequired bool
	// Location is the location of the upstream proxy. It is used as the location to Dial on the upstream server
	// for upgrade requests unless UseRequestLocationOnUpgrade is true.
	Location *url.URL
	// Transport provides an optional round tripper to use to proxy. If nil, the default proxy transport is used
	Transport http.RoundTripper
	// UpgradeTransport, if specified, will be used as the backend transport when upgrade requests are provided.
	// This allows clients to disable HTTP/2.
	UpgradeTransport UpgradeRequestRoundTripper
	// WrapTransport indicates whether the provided Transport should be wrapped with default proxy transport behavior (URL rewriting, X-Forwarded-* header setting)
	WrapTransport bool
	// InterceptRedirects determines whether the proxy should sniff backend responses for redirects,
	// following them as necessary.
	InterceptRedirects bool
	// RequireSameHostRedirects only allows redirects to the same host. It is only used if InterceptRedirects=true.
	RequireSameHostRedirects bool
	// UseRequestLocation will use the incoming request URL when talking to the backend server.
	UseRequestLocation bool
	// UseLocationHost overrides the HTTP host header in requests to the backend server to use the Host from Location.
	// This will override the req.Host field of a request, while UseRequestLocation will override the req.URL field
	// of a request. The req.URL.Host specifies the server to connect to, while the req.Host field
	// specifies the Host header value to send in the HTTP request. If this is false, the incoming req.Host header will
	// just be forwarded to the backend server.
	UseLocationHost bool
	// FlushInterval controls how often the standard HTTP proxy will flush content from the upstream.
	FlushInterval time.Duration
	// MaxBytesPerSec controls the maximum rate for an upstream connection. No rate is imposed if the value is zero.
	MaxBytesPerSec int64
	// Responder is passed errors that occur while setting up proxying.
	Responder ErrorResponder
}

UpgradeAwareHandler is a handler for proxy requests that may require an upgrade

func NewUpgradeAwareHandler

func NewUpgradeAwareHandler(location *url.URL, transport http.RoundTripper, wrapTransport, upgradeRequired bool, responder ErrorResponder) *UpgradeAwareHandler

NewUpgradeAwareHandler creates a new proxy handler with a default flush interval. Responder is required for returning errors to the caller.

func (*UpgradeAwareHandler) DialForUpgrade

func (h *UpgradeAwareHandler) DialForUpgrade(req *http.Request) (net.Conn, error)

func (*UpgradeAwareHandler) ServeHTTP

func (h *UpgradeAwareHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP handles the proxy request

type UpgradeRequestRoundTripper

type UpgradeRequestRoundTripper interface {
	http.RoundTripper
	// WrapRequest takes a valid HTTP request and returns a suitably altered version
	// of request with any HTTP level values required to complete the request half of
	// an upgrade on the server. It does not get a chance to see the response and
	// should bypass any request side logic that expects to see the response.
	WrapRequest(*http.Request) (*http.Request, error)
}

UpgradeRequestRoundTripper provides an additional method to decorate a request with any authentication or other protocol level information prior to performing an upgrade on the server. Any response will be handled by the intercepting proxy.

func NewUpgradeRequestRoundTripper

func NewUpgradeRequestRoundTripper(connection, request http.RoundTripper) UpgradeRequestRoundTripper

NewUpgradeRequestRoundTripper takes two round trippers - one for the underlying TCP connection, and one that is able to write headers to an HTTP request. The request rt is used to set the request headers and that is written to the underlying connection rt.

Jump to

Keyboard shortcuts

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