httpreverseproxy

package
v1.88.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package httpreverseproxy provides an HTTP Reverse Proxy that takes an incoming request and sends it to another server, proxying the response back to the client. It wraps the standard net/http/httputil ReverseProxy (or equivalent) with common functionalities, including logging and error handling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client implements the Reverse Proxy.

func New

func New(addr string, opts ...Option) (*Client, error)

New returns a new instance of the Client.

func (*Client) ForwardRequest

func (c *Client) ForwardRequest(w http.ResponseWriter, r *http.Request)

ForwardRequest forwards a request to the proxied service.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient contains the function to perform the HTTP request to the proxied service.

type Option

type Option func(c *Client)

Option is the interface that allows to set client options.

func WithHTTPClient

func WithHTTPClient(h HTTPClient) Option

WithHTTPClient overrides the default HTTP client used to forward the requests. The HTTP client can contain extra logic for logging.

func WithLogger

func WithLogger(l *zap.Logger) Option

WithLogger overrides the default logger.

func WithReverseProxy

func WithReverseProxy(p *httputil.ReverseProxy) Option

WithReverseProxy overrides the default httputil.ReverseProxy. Leave the Director and Transport entries nil to be automatically set. If the Director entry is specified, then the addr argument of the New function is ignored. If the Transport entry is specified, then the HTTP client specified with WithHTTPClient is ignored.

Jump to

Keyboard shortcuts

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