httpproxy

package
v0.55.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package httpproxy implements the proxy forwarding the requests to the datasources reachable over HTTP (datasource proxy kind "HTTPProxy").

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Proxy

type Proxy struct {
	// Config is the HTTP proxy configuration of the datasource (URL, allowed endpoints, headers...). It is required.
	Config *datasourceHTTP.Config
	// Secret contains the credentials and the TLS config used to reach the datasource. It must already be decrypted.
	// It can be nil.
	Secret *v1.SecretSpec
	// DatasourceName is the name of the datasource, used in the logs and in the error messages.
	DatasourceName string
	// Path is the path of the request on the datasource side. It must start with a '/'.
	Path string
	// Guard verifies every connection made by the proxy. It is required.
	Guard *netguard.Guard
	// TokenRefresher refreshes the OIDC token of the caller when it is missing,
	// for the datasources using the OAuth passthrough. It can be nil.
	TokenRefresher crypto.TokenRefresher
	// Transports caches the HTTP transports of the saved datasources. It can be nil.
	Transports *TransportCache
	// TransportKey identifies the datasource in the transport cache. It is opaque to the proxy.
	// Empty for unsaved datasources: their transport is not cached, and the events they cause are logged at debug level.
	TransportKey string
	// ProxyConfig contains the connection limits and timeouts applied to the transport (datasource.proxy.http).
	// Unset values fall back to their defaults.
	ProxyConfig config.HTTPProxyConfig
	// ForwardCallerAuthorization defines if the Authorization header sent by the caller can be forwarded to the datasource.
	// The zero value (false) is the safe default: the header is removed.
	ForwardCallerAuthorization bool
}

Proxy forwards a request to a datasource reachable over HTTP (datasource proxy kind "HTTPProxy"). It must be built with New, once per request to forward.

Before forwarding the request, the proxy removes the credentials the caller uses to authenticate against Perses, applies the header policies of the datasource and sets up the authentication defined by its secret. Every connection it makes (to the datasource, but also to the OAuth token endpoint) is verified by the Guard.

func New

func New(p Proxy) (*Proxy, error)

New returns the Proxy described by p, once verified it holds the settings required to serve requests safely: the config of the datasource (with its URL) and the Guard.

func (*Proxy) Serve

func (h *Proxy) Serve(c echo.Context) error

Serve forwards the request of c to the datasource, and writes the response of the datasource to c. The response is served under the Perses origin, so the headers that would apply to it are removed or overridden (see secureResponse).

type TransportCache

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

TransportCache keeps one *http.Transport per saved datasource, so connections (TCP + TLS) to the datasource are reused across requests instead of being re-established for every proxied request.

An entry is identified by the datasource identity. The transport is rebuilt when:

  • the settings of the transport change (see transportSettings), like the TLS config of the secret or the connection timeout (detected with a hash of the settings. Only the hash is kept in memory, never the TLS config itself),
  • the CA file referenced by the TLS config changes on disk (detected with its modification time and size),
  • the transport expires (see transportMaxLifetime).

func NewTransportCache

func NewTransportCache() *TransportCache

NewTransportCache returns an empty TransportCache. It is meant to be shared by all the proxies for the lifetime of the server, so the transports are reused across requests.

Jump to

Keyboard shortcuts

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