http

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const TrailerPrefix = "Trailer:"

TrailerPrefix is a magic prefix for [ResponseWriter.Header] map keys that, if present, signals that the map entry is actually for the response trailers, and not the response headers. The prefix is stripped after the ServeHTTP call finishes and the values are sent in the trailers.

This mechanism is intended only for trailers that are not known prior to the headers being written. If the set of trailers is fixed or known before the header is written, the normal Go trailers mechanism is preferred:

https://pkg.go.dev/net/http#ResponseWriter
https://pkg.go.dev/net/http#example-ResponseWriter-Trailers

Variables

This section is empty.

Functions

func DefaultClientOptions

func DefaultClientOptions() []hzconfig.ClientOption

DefaultClientOptions returns a set of default Hertz client options for proxying.

func IsASCIIPrint

func IsASCIIPrint(s string) bool

IsASCIIPrint returns whether s is ASCII and printable according to https://tools.ietf.org/html/rfc20#section-4.2.

func JoinURLPath

func JoinURLPath(req *protocol.Request, target string) (path []byte)

JoinURLPath joins the request path with the target URL path, correctly handling slashes.

func New

func New(opts Options, httpClient *client.Client) (proxy.Proxy, error)

New creates a new reverse proxy instance.

func NewClient

func NewClient(opts ClientOptions) (*client.Client, error)

NewClient creates a new Hertz client with the given options.

func NewClientFactory added in v0.9.0

func NewClientFactory(tlsConfig *tls.Config) suite.ClientFactory

NewClientFactory creates a new stdlibFactory.

Types

type ClientOptions

type ClientOptions struct {
	HZOptions []hzconfig.ClientOption
	IsHTTP2   bool
}

ClientOptions defines the configuration for a Hertz HTTP client.

type Options

type Options struct {
	Target           string
	TargetHostHeader string
	ServiceID        string
	Protocol         config.Protocol
	MaxFails         uint
	FailTimeout      time.Duration
	Weight           uint32
	IsTracingEnabled bool
	PassHostHeader   bool
	Tags             map[string]string
}

Options contains configuration for the HTTP proxy.

type Proxy added in v0.10.0

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

Proxy implements a reverse proxy for HTTP services.

func (*Proxy) AddFailedCount added in v0.10.0

func (p *Proxy) AddFailedCount(count uint) error

AddFailedCount increments the failed request count for the proxy.

func (*Proxy) Close added in v0.10.0

func (p *Proxy) Close() error

Close closes the proxy and its underlying idle connections.

func (*Proxy) ID added in v0.10.0

func (p *Proxy) ID() string

ID return proxy's ID.

func (*Proxy) IsAvailable added in v0.10.0

func (p *Proxy) IsAvailable() bool

IsAvailable checks if the proxy is currently available.

func (*Proxy) ServeHTTP added in v0.10.0

func (p *Proxy) ServeHTTP(ctx context.Context, c *app.RequestContext)

func (*Proxy) SetClient added in v0.10.0

func (p *Proxy) SetClient(httpClient *client.Client)

SetClient sets the HTTP client for the proxy.

func (*Proxy) SetDirector added in v0.10.0

func (p *Proxy) SetDirector(director func(req *protocol.Request))

SetDirector use to customize protocol.Request.

func (*Proxy) SetErrorHandler added in v0.10.0

func (p *Proxy) SetErrorHandler(eh func(c *app.RequestContext, err error))

SetErrorHandler use to customize error handler.

func (*Proxy) SetTransferTrailer added in v0.10.0

func (p *Proxy) SetTransferTrailer(b bool)

SetTransferTrailer sets whether to forward trailer headers.

func (*Proxy) Tag added in v0.10.0

func (p *Proxy) Tag(key string) (value string, exist bool)

Tag returns the value of a specific tag.

func (*Proxy) Tags added in v0.10.0

func (p *Proxy) Tags() map[string]string

Tags returns all tags associated with the proxy.

func (*Proxy) Target added in v0.10.0

func (p *Proxy) Target() string

Target returns the target URL string of the proxy.

func (*Proxy) Weight added in v0.10.0

func (p *Proxy) Weight() uint32

Weight returns the load balancing weight of the proxy.

Jump to

Keyboard shortcuts

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