Documentation
¶
Index ¶
- Constants
- func DefaultClientOptions() []hzconfig.ClientOption
- func IsASCIIPrint(s string) bool
- func JoinURLPath(req *protocol.Request, target string) (path []byte)
- func New(opts Options, httpClient *client.Client) (proxy.Proxy, error)
- func NewClient(opts ClientOptions) (*client.Client, error)
- func NewClientFactory(tlsConfig *tls.Config) suite.ClientFactory
- type ClientOptions
- type Options
- type Proxy
- func (p *Proxy) AddFailedCount(count uint) error
- func (p *Proxy) Close() error
- func (p *Proxy) ID() string
- func (p *Proxy) IsAvailable() bool
- func (p *Proxy) ServeHTTP(ctx context.Context, c *app.RequestContext)
- func (p *Proxy) SetClient(httpClient *client.Client)
- func (p *Proxy) SetDirector(director func(req *protocol.Request))
- func (p *Proxy) SetErrorHandler(eh func(c *app.RequestContext, err error))
- func (p *Proxy) SetTransferTrailer(b bool)
- func (p *Proxy) Tag(key string) (value string, exist bool)
- func (p *Proxy) Tags() map[string]string
- func (p *Proxy) Target() string
- func (p *Proxy) Weight() uint32
Constants ¶
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 ¶
IsASCIIPrint returns whether s is ASCII and printable according to https://tools.ietf.org/html/rfc20#section-4.2.
func JoinURLPath ¶
JoinURLPath joins the request path with the target URL path, correctly handling slashes.
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
AddFailedCount increments the failed request count for the proxy.
func (*Proxy) IsAvailable ¶ added in v0.10.0
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) SetDirector ¶ added in v0.10.0
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
SetTransferTrailer sets whether to forward trailer headers.