Documentation ¶
Index ¶
- Constants
- Variables
- func BodyRewindableWithFile(file *os.File) (body io.ReadCloser, getBody func() (io.ReadCloser, error), err error)
- func BodyRewindableWithFilePosition(name string, offset int64, whence int) (body io.ReadCloser, getBody func() (io.ReadCloser, error), err error)
- func ClientIP(req *http.Request) string
- func CloneMultipartFileHeader(fh *multipart.FileHeader) *multipart.FileHeader
- func CloneMultipartForm(f *multipart.Form) *multipart.Form
- func CloneOrMakeHeader(hdr http.Header) http.Header
- func CloneTLSConfig(cfg *tls.Config) *tls.Config
- func CloneURL(u *url.URL) *url.URL
- func CloneURLValues(v url.Values) url.Values
- func ContentType(r io.Reader, name string) (ctype string, bufferedContent io.Reader, err error)
- func DoJson(httpReq *http.Request, req, resp any) error
- func DoJsonWithBackoff(httpReq *http.Request, req, resp any, opts ...DoWithBackoffOption) error
- func DoWithBackoff(httpReq *http.Request, opts ...DoWithBackoffOption) (resp *http.Response, err error)
- func DoesRequestSatisfyTlsTermination(r *http.Request, whitelistedPaths []string, allowedTLSCIDRs []string) error
- func FromHTTPContext(r *http.Request, keys ...any) string
- func Get(url string) (resp *http.Response, err error)
- func GetProxySchemeAndHost(r *http.Request, allowForwarded bool) (scheme, host string)
- func GetWithBackoff(ctx context.Context, url string, opts ...DoWithBackoffOption) (*http.Response, error)
- func Head(url string) (resp *http.Response, err error)
- func HeadWithBackoff(ctx context.Context, url string, opts ...DoWithBackoffOption) (*http.Response, error)
- func HostFuncFromContext(req *http.Request) error
- func NewRecordResponseWriter(rw http.ResponseWriter) *recordResponseWriter
- func Post(url, contentType string, body io.Reader) (resp *http.Response, err error)
- func PostForm(url string, data url.Values) (resp *http.Response, err error)
- func PostFormWithBackoff(ctx context.Context, url string, data url.Values, opts ...DoWithBackoffOption) (resp *http.Response, err error)
- func PostWithBackoff(ctx context.Context, url, contentType string, body io.Reader, ...) (resp *http.Response, err error)
- func ProxyFuncFromContextOrEnvironment(req *http.Request) (*url.URL, error)
- func ProxyFuncWithTargetOrDefault(fixedProxyUrl string, fixedProxyTarget string, ...) func(req *http.Request) (*url.URL, error)
- func PutWithBackoff(ctx context.Context, url, contentType string, body io.Reader, ...) (resp *http.Response, err error)
- func Recover(writer io.Writer, req *http.Request, recoverHandler func(err any) any) any
- func RecoveryClientInterceptor(next http.RoundTripper, out io.Writer, ...) http.RoundTripper
- func RecoveryServerInterceptor(next http.Handler, out io.Writer, ...) http.Handler
- func RejectInsecureServerInterceptor(next http.Handler, opts ...RejectInsecureOption) *rejectInsecure
- func ReplaceHttpRequestBody(req *http.Request, body io.Reader)
- func ReplacePath(path string, h http.Handler) http.Handler
- func RequestIDFromContext(ctx context.Context) string
- func RequestRewindableWithFileName(name string) (body io.ReadCloser, getBody func() (io.ReadCloser, error), err error)
- func RequestWithBodyRewindable(req *http.Request) error
- func RequestWithHostTarget(req *http.Request, target *httphost.Host) *http.Request
- func RequestWithProxyTarget(req *http.Request, proxy *httpproxy.Proxy) *http.Request
- func ResolveProxyUrl(u *url.URL, r *http.Request, allowForwarded bool) *url.URL
- func RetryAfter(resp *http.Response, err error, defaultBackoff time.Duration) (backoff time.Duration, retry bool)
- func RoundTripperWithBackoff(rt http.RoundTripper, opts ...DoWithBackoffOption) http.RoundTripper
- func RoundTripperWithTarget(rt http.RoundTripper) http.RoundTripper
- func ServeContent(w http.ResponseWriter, r *http.Request, name string, modtime time.Time, ...)
- func ServerWithDefaults(srv *http.Server) *http.Server
- func SetInOutMetadata(ctx context.Context, w http.ResponseWriter, r *http.Request, requestID string) context.Context
- func TransportWithProxyTarget(t *http.Transport, fixedProxyUrl string, fixedProxyTarget string) *http.Transport
- func WarnText(code int) string
- type Client
- func (c *Client) Do(req *http.Request) (_ *http.Response, err error)
- func (c *Client) Get(url string) (resp *http.Response, err error)
- func (c *Client) Head(url string) (resp *http.Response, err error)
- func (c *Client) Post(url string, contentType string, body io.Reader) (resp *http.Response, err error)
- func (c *Client) PostForm(url string, data url.Values) (resp *http.Response, err error)
- func (c *Client) Use(d ...RoundTripDecorator) *Client
- type ClientInterceptor
- type ClientInvoker
- type DoRetryHandler
- type DoWithBackoffOption
- func WithDoWithBackoffOptionChainUnaryInterceptor(interceptors ...ClientInterceptor) DoWithBackoffOption
- func WithDoWithBackoffOptionDoRetryHandler(f DoRetryHandler) DoWithBackoffOption
- func WithDoWithBackoffOptionExponentialBackOffOption(opts ...time_.ExponentialBackOffOption) DoWithBackoffOption
- func WithDoWithBackoffOptionGrpcBackOff(retries int) DoWithBackoffOption
- func WithDoWithBackoffOptionMaxRetries(retries int) DoWithBackoffOption
- func WithDoWithBackoffOptionProxy(proxyUrl string, proxyTarget string) DoWithBackoffOption
- func WithDoWithBackoffOptionRetryAfter(f RetryAfterHandler) DoWithBackoffOption
- func WithDoWithBackoffOptionRoundTripper(rt http.RoundTripper) DoWithBackoffOption
- func WithDoWithBackoffOptionTarget(target string) DoWithBackoffOption
- type DoWithBackoffOptionFunc
- type EmptyDoWithBackoffOption
- type EmptyHandlerInterceptorChainOption
- type EmptyRejectInsecureOption
- type HandlerDecorator
- type HandlerDecorators
- type HandlerInterceptorChain
- type HandlerInterceptorChainOption
- type HandlerInterceptorChainOptionFunc
- type RejectInsecureOption
- func RejectInsecureWithAllowedTlsCidrs(allowedTLSCIDRs []string) RejectInsecureOption
- func RejectInsecureWithErrorLog(l *log.Logger) RejectInsecureOption
- func RejectInsecureWithForceHttp(forceHttp bool) RejectInsecureOption
- func RejectInsecureWithWhitelistedPaths(whitelistedPaths []string) RejectInsecureOption
- type RejectInsecureOptionFunc
- type RetryAfterHandler
- type RoundTripDecorator
- type RoundTripDecorators
- type RoundTripFunc
- type Warn
Constants ¶
const ( WarnResponseIsStale = 110 // RFC 7234, 5.5.1 WarnRevalidationFailed = 111 // RFC 7234, 5.5.2 WarnDisconnectedOperation = 112 // RFC 7234, 5.5.3 WarnHeuristicExpiration = 113 // RFC 7234, 5.5.4 WarnMiscellaneousWarning = 199 // RFC 7234, 5.5.5 WarnTransformationApplied = 214 // RFC 7234, 5.5.6 WarnMiscellaneousPersistentWarning = 299 // RFC 7234, 5.5.7 )
HTTP warn codes as registered with IANA. See: https://www.iana.org/assignments/http-warn-codes/http-warn-codes.xhtml See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Warning#warning_codes Deprecated: The "Warning" header field was used to carry additional information about the status or transformation of a message that might not be reflected in the status code. This specification obsoletes it, as it is not widely generated or surfaced to users. The information it carried can be gleaned from examining other header fields, such as Age. See: https://www.rfc-editor.org/rfc/rfc9111.html#name-warning
Variables ¶
var ( // DefaultCurvePreferences defines the recommended elliptic curves for modern TLS DefaultCurvePreferences = []tls.CurveID{ tls.CurveP256, tls.X25519, } // DefaultCipherSuites defines the recommended cipher suites for modern TLS DefaultCipherSuites = []uint16{ tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, } // DefaultMinVersion defines the recommended minimum version to use for the TLS protocol (1.2) DefaultMinVersion uint16 = tls.VersionTLS12 // DefaultReadTimeout sets the maximum time a client has to fully stream a request (5s) DefaultReadTimeout = 5 * time.Second // DefaultWriteTimeout sets the maximum amount of time a handler has to fully process a request (10s) DefaultWriteTimeout = 10 * time.Second // DefaultIdleTimeout sets the maximum amount of time a Keep-Alive connection can remain idle before // being recycled (120s) DefaultIdleTimeout = 120 * time.Second )
var DefaultClientDoRetryHandler = func(req *http.Request, retry int) (*http.Response, error) { return http.DefaultClient.Do(req) }
var DefaultClientWithDynamicHost = &http.Client{ Transport: DefaultTransportWithDynamicHost, }
DefaultClientWithDynamicHost is the default Client with DefaultTransportWithDynamicHost.
var DefaultClientWithDynamicHostAndProxy = &http.Client{ Transport: DefaultTransportWithDynamicHostAndProxy, }
DefaultClientWithDynamicHostAndProxy is the default Client with DefaultTransportWithDynamicHostAndProxy.
var DefaultClientWithDynamicProxy = &http.Client{ Transport: DefaultTransportWithDynamicProxy, }
DefaultClientWithDynamicProxy is the default Client with DefaultTransportWithDynamicProxy.
var DefaultTransportDoRetryHandler = func(req *http.Request, retry int) (*http.Response, error) { return http.DefaultTransport.RoundTrip(req) }
var DefaultTransportWithDynamicHost = RoundTripperWithTarget(http.DefaultTransport)
DefaultTransportWithDynamicHost is the default implementation of Transport and is used by DefaultClientWithDynamicHost. It establishes network connections as needed and caches them for reuse by subsequent calls.
var DefaultTransportWithDynamicHostAndProxy = RoundTripperWithTarget(DefaultTransportWithDynamicProxy)
DefaultTransportWithDynamicHostAndProxy is the default implementation of Transport and is used by DefaultClientWithDynamicHostAndProxy. It establishes network connections as needed and caches them for reuse by subsequent calls.
var DefaultTransportWithDynamicProxy http.RoundTripper = &http.Transport{ Proxy: ProxyFuncFromContextOrEnvironment, DialContext: (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, }).DialContext, ForceAttemptHTTP2: true, MaxIdleConns: 100, IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, }
DefaultTransportWithDynamicProxy is the default implementation of Transport and is used by DefaultClientWithDynamicProxy. It establishes network connections as needed and caches them for reuse by subsequent calls. It uses HTTP proxies as directed by the ProxyFuncFromContextOrEnvironment, $HTTP_PROXY and $NO_PROXY (or $http_proxy and $no_proxy) environment variables.
var DefaultXRequestIDKey = "X-Request-ID"
DefaultXRequestIDKey is metadata key name for request ID
var (
ErrBodyNotRewindable = errors.New("body not rewindable")
)
var Methods = []string{ http.MethodGet, http.MethodHead, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete, http.MethodConnect, http.MethodOptions, http.MethodTrace, }
Functions ¶
func BodyRewindableWithFile ¶
func BodyRewindableWithFile(file *os.File) (body io.ReadCloser, getBody func() (io.ReadCloser, error), err error)
BodyRewindableWithFile returns a Request suitable for use with Redirect, like 307 redirect for PUT or POST. Only a nil GetBody in Request may be replace with a rewindable GetBody, which is a Body *os.File. See: https://github.com/golang/go/issues/7912 See also: https://go-review.googlesource.com/c/go/+/29852/13/src/net/http/client.go#391
func BodyRewindableWithFilePosition ¶
func BodyRewindableWithFilePosition(name string, offset int64, whence int) (body io.ReadCloser, getBody func() (io.ReadCloser, error), err error)
func ClientIP ¶
ClientIP implements a best effort algorithm to return the real client IP, it parses X-Real-IP and X-Forwarded-For in order to work properly with reverse-proxies such us: nginx or haproxy. Use X-Forwarded-For before X-Real-Ip as nginx uses X-Real-Ip with the proxy's IP.
func CloneMultipartFileHeader ¶
func CloneMultipartFileHeader(fh *multipart.FileHeader) *multipart.FileHeader
func CloneOrMakeHeader ¶
CloneOrMakeHeader invokes Header.Clone but if the result is nil, it'll instead make and return a non-nil Header.
func CloneTLSConfig ¶
CloneTLSConfig returns a shallow clone of cfg, or a new zero tls.Config if cfg is nil. This is safe to call even if cfg is in active use by a TLS client or server.
func ContentType ¶
ContentType implements the algorithm described at https://mimesniff.spec.whatwg.org/ to determine the Content-Type of the given data. It considers at most the first 512 bytes of data from r. ContentType always returns a valid MIME type: if it cannot determine a more specific one, it returns "application/octet-stream". ContentType is based on http.DetectContentType.
func DoJsonWithBackoff ¶
func DoJsonWithBackoff(httpReq *http.Request, req, resp any, opts ...DoWithBackoffOption) error
DoJsonWithBackoff the same as DoWithBackoff, but bind with json
func DoWithBackoff ¶
func DoWithBackoff(httpReq *http.Request, opts ...DoWithBackoffOption) (resp *http.Response, err error)
DoWithBackoff will retry by exponential backoff if failed. If request is not rewindable, retry wil be skipped.
func DoesRequestSatisfyTlsTermination ¶
func DoesRequestSatisfyTlsTermination(r *http.Request, whitelistedPaths []string, allowedTLSCIDRs []string) error
DoesRequestSatisfyTlsTermination returns whether the request fulfills tls's constraints, https, path matches any whitelisted paths or ip inclued by any cidr whitelistedPath is http path that does not need to be checked allowedTLSCIDR is the network includes ip.
func FromHTTPContext ¶
FromHTTPContext parse request id from gin.Context query | header | post form | context 从请求中提取request-id
func GetProxySchemeAndHost ¶
GetProxySchemeAndHost extracts the host and used protocol (either HTTP or HTTPS) from the given request. If `allowForwarded` is set, the X-Forwarded-Host, X-Forwarded-Proto and Forwarded headers will also be checked to support proxies.
func GetWithBackoff ¶
func HeadWithBackoff ¶
func HostFuncFromContext ¶ added in v1.2.55
HostFuncFromContext builds a host function from the given string, which should represent a Target that can be used as a host. It performs basic sanitization of the Target retrieved in context of Request, and returns any error encountered.
func NewRecordResponseWriter ¶ added in v1.2.94
func NewRecordResponseWriter(rw http.ResponseWriter) *recordResponseWriter
NewRecordResponseWriter creates a ResponseWriter that is a wrapper around http.ResponseWriter that provides extra information about the response. It is recommended that middleware handlers use this construct to wrap a http.ResponseWriter if the functionality calls for it.
func PostFormWithBackoff ¶
func PostWithBackoff ¶
func ProxyFuncFromContextOrEnvironment ¶ added in v1.2.52
ProxyFuncFromContextOrEnvironment builds a proxy function from the given string, which should represent a Target that can be used as a proxy. It performs basic sanitization of the Target retrieved in context of Request, and returns any error encountered.
func ProxyFuncWithTargetOrDefault ¶
func ProxyFuncWithTargetOrDefault(fixedProxyUrl string, fixedProxyTarget string, def func(req *http.Request) (*url.URL, error)) func(req *http.Request) (*url.URL, error)
ProxyFuncWithTargetOrDefault builds a proxy function from the given string, which should represent a Target that can be used as a proxy. It performs basic sanitization of the Target and returns any error encountered. fixedProxyUrl is proxy's url, like socks5://127.0.0.1:8080 fixedProxyTarget is as like gRPC Naming for proxy service discovery, with Host in TargetUrl replaced if not empty.
func PutWithBackoff ¶
func RecoveryClientInterceptor ¶
func RecoveryClientInterceptor(next http.RoundTripper, out io.Writer, f func(resp *http.Response, req *http.Request, err any)) http.RoundTripper
RecoveryClientInterceptor returns a new client interceptors with recovery from panic. affect as recover{f()}; next()
func RecoveryServerInterceptor ¶
func RecoveryServerInterceptor(next http.Handler, out io.Writer, f func(w http.ResponseWriter, r *http.Request, err any)) http.Handler
RecoveryServerInterceptor returns a new server interceptors with recovery from panic. affect as recover{f()}; next()
func RejectInsecureServerInterceptor ¶
func RejectInsecureServerInterceptor(next http.Handler, opts ...RejectInsecureOption) *rejectInsecure
RejectInsecureServerInterceptor returns a new server interceptor with tls check. reject the request fulfills tls's constraints,
func ReplaceHttpRequestBody ¶
ReplaceHttpRequestBody replace Body and recalculate ContentLength If ContentLength should not be recalculated, save and restore it after ReplaceHttpRequestBody
func ReplacePath ¶
StripPrefix returns a handler that serves HTTP requests by removing the given prefix from the request URL's Path and invoking the handler h. StripPrefix handles a request for a path that doesn't begin with prefix by replying with an HTTP 404 not found error.
func RequestIDFromContext ¶
func RequestRewindableWithFileName ¶
func RequestRewindableWithFileName(name string) (body io.ReadCloser, getBody func() (io.ReadCloser, error), err error)
func RequestWithBodyRewindable ¶
RequestWithBodyRewindable returns a Request suitable for use with Redirect, like 307 redirect for PUT or POST. Only a nil GetBody in Request may be replaced with a rewindable GetBody, which is a Body replayer. A body with a type not io.NopCloser(nil) may return error as the Body in Request will be closed before redirect automatically. So you can close body by yourself to ensure rewindable always: Examples:
body := req.Body defer body.Close() // body will not be closed inside req.Body = io.NopCloser(body) _ = RequestWithBodyRewindable(req)
// do http requests...
See: https://github.com/golang/go/issues/7912 See also: https://go-review.googlesource.com/c/go/+/29852/13/src/net/http/client.go#391
func RequestWithHostTarget ¶ added in v1.2.55
RequestWithHostTarget replace Host in url.Url by resolver.Host replace Host in req if replaceHostInRequest is true
func RequestWithProxyTarget ¶ added in v1.2.52
RequestWithProxyTarget returns a shallow copy of r with its context changed to ctx, TargetUrl and Host inside. The provided ctx must be non-nil. proxyUrl is proxy's url, like socks5://127.0.0.1:8080 proxyTarget is as like gRPC Naming for proxy service discovery, with Host in TargetUrl replaced if not empty.
func ResolveProxyUrl ¶
ResolveProxyUrl resolves a URI reference to a URI from a URI u and origin [scheme,host] forwarded behind proxy in r. ResolveProxyUrl always returns a new URL instance, even if the returned URL is identical to either the base or reference.
func RetryAfter ¶
func RetryAfter(resp *http.Response, err error, defaultBackoff time.Duration) (backoff time.Duration, retry bool)
RetryAfter tries to parse Retry-After response header when a http.StatusTooManyRequests (HTTP Code 429) is found in the resp parameter. Hence, it will return the number of seconds the server states it may be ready to process more requests from this client. Don't retry if the error was due to too many redirects. Don't retry if the error was due to an invalid protocol scheme. Don't retry if the error was due to TLS cert verification failure. Don't retry if the http's StatusCode is http.StatusNotImplemented.
func RoundTripperWithBackoff ¶
func RoundTripperWithBackoff(rt http.RoundTripper, opts ...DoWithBackoffOption) http.RoundTripper
RoundTripperWithBackoff wraps http.RoundTripper retryable by backoff.
func RoundTripperWithTarget ¶
func RoundTripperWithTarget(rt http.RoundTripper) http.RoundTripper
RoundTripperWithTarget wraps http.RoundTripper with request url replaced by Target resolved by resolver. Target is as like gRPC Naming for service discovery.
func ServeContent ¶
func ServeContent(w http.ResponseWriter, r *http.Request, name string, modtime time.Time, content io.Reader, size int64)
ServeContent replies to the request using the content in the provided Reader. The main benefit of ServeContent over io.Copy is that it handles Range requests properly, sets the MIME type, and handles If-Match, If-Unmodified-Since, If-None-Match, If-Modified-Since, and If-Range requests.
If the response's Content-Type header is not set, ServeContent first tries to deduce the type from name's file extension and, if that fails, falls back to reading the first block of the content and passing it to DetectContentType. The name is otherwise unused; in particular it can be empty and is never sent in the response.
If modtime is not the zero time or Unix epoch, ServeContent includes it in a Last-Modified header in the response. If the request includes an If-Modified-Since header, ServeContent uses modtime to decide whether the content needs to be sent at all.
If the content's Seek method work: ServeContent uses a seek to the end of the content to determine its size, and the param size is ignored. The same as http.ServeFile If the content's Seek method doesn't work: ServeContent uses the param size to generate a onlySizeSeekable as a pseudo io.ReadSeeker. If size < 0, use chunk or connection close instead
If the caller has set w's ETag header formatted per RFC 7232, section 2.3, ServeContent uses it to handle requests using If-Match, If-None-Match, or If-Range.
Note that *os.File implements the io.ReadSeeker interface.
func ServerWithDefaults ¶
ServerWithDefaults patches a http.Server based on a best practice configuration from Cloudflare: https://blog.cloudflare.com/exposing-go-on-the-internet/
You can override the defaults by mutating the Default* variables exposed by this package
func SetInOutMetadata ¶
func SetInOutMetadata(ctx context.Context, w http.ResponseWriter, r *http.Request, requestID string) context.Context
SetInOutMetadata injects requestIDs in req|resp's Header and context 将request-id追加注入请求|响应头及context中
func TransportWithProxyTarget ¶
func TransportWithProxyTarget(t *http.Transport, fixedProxyUrl string, fixedProxyTarget string) *http.Transport
TransportWithProxyTarget wraps http.RoundTripper with request url replaced by Target resolved by resolver. fixedProxyUrl is proxy's url, like socks5://127.0.0.1:8080 fixedProxyTarget is as like gRPC Naming for proxy service discovery, with Host in TargetUrl replaced if not empty.
Types ¶
type Client ¶
func NewClient ¶
NewClient returns a http client wrapper behaves like http.Client, sends HTTP Request to target by proxy url with Host replaced by proxyTarget
u is the original url to send HTTP request, empty usually. target is the resolver to resolve Host to send HTTP request, that is replacing host in url(NOT HOST in http header) by address resolved by Host fixedProxyUrl is proxy's url, like socks5://127.0.0.1:8080 fixedProxyTarget is as like gRPC Naming for proxy service discovery, with Host in TargetUrl replaced if not empty.
func NewClientWithProxy ¶ added in v1.2.21
NewClientWithProxy returns a Client with http.Client with proxy set by resolver.Host TargetUrl is proxy's url, like socks5://127.0.0.1:8080 Host is proxy's addr, replace the HOST in TargetUrl if not empty
func NewClientWithTarget ¶
NewClientWithTarget returns a Client with http.Client and host replaced by resolver.Host target is the resolver to resolve Host to send HTTP request, that is replacing host in url(NOT HOST in http header) by address resolved by Host
func (*Client) Use ¶
func (c *Client) Use(d ...RoundTripDecorator) *Client
Use adds middleware handlers to the transport.
type ClientInterceptor ¶
type ClientInterceptor func(req *http.Request, retry int, invoker ClientInvoker, opts ...DoWithBackoffOption) (resp *http.Response, err error)
ClientInterceptor intercepts the execution of a HTTP on the client. interceptors can be specified as a DoWithBackoffOption, using WithClientInterceptor() or WithChainClientInterceptor(), when DoWithBackoffOption. When a interceptor(s) is set, gRPC delegates all http invocations to the interceptor, and it is the responsibility of the interceptor to call invoker to complete the processing of the HTTP.
type ClientInvoker ¶
ClientInvoker is called by ClientInterceptor to complete RPCs.
type DoRetryHandler ¶
type DoRetryHandler = ClientInvoker
DoRetryHandler send an HTTP request with retry seq and returns an HTTP response, following policy (such as redirects, cookies, auth) as configured on the client.
type DoWithBackoffOption ¶
type DoWithBackoffOption interface {
// contains filtered or unexported methods
}
A DoWithBackoffOption sets options.
func WithDoWithBackoffOptionChainUnaryInterceptor ¶
func WithDoWithBackoffOptionChainUnaryInterceptor(interceptors ...ClientInterceptor) DoWithBackoffOption
WithDoWithBackoffOptionChainUnaryInterceptor returns a DoWithBackoffOption that specifies the chained interceptor for http clients. The first interceptor will be the outer most, while the last interceptor will be the inner most wrapper around the real call. All interceptors added by this method will be chained, and the interceptor defined by WithClientInterceptor will always be prepended to the chain.
func WithDoWithBackoffOptionDoRetryHandler ¶
func WithDoWithBackoffOptionDoRetryHandler(f DoRetryHandler) DoWithBackoffOption
func WithDoWithBackoffOptionExponentialBackOffOption ¶
func WithDoWithBackoffOptionExponentialBackOffOption(opts ...time_.ExponentialBackOffOption) DoWithBackoffOption
func WithDoWithBackoffOptionGrpcBackOff ¶
func WithDoWithBackoffOptionGrpcBackOff(retries int) DoWithBackoffOption
func WithDoWithBackoffOptionMaxRetries ¶
func WithDoWithBackoffOptionMaxRetries(retries int) DoWithBackoffOption
func WithDoWithBackoffOptionProxy ¶
func WithDoWithBackoffOptionProxy(proxyUrl string, proxyTarget string) DoWithBackoffOption
WithDoWithBackoffOptionProxy returns a DoWithBackoffOption. TargetUrl is proxy's url, like socks5://127.0.0.1:8080 Host is proxy's addr, replace the HOST in TargetUrl if not empty
func WithDoWithBackoffOptionRetryAfter ¶
func WithDoWithBackoffOptionRetryAfter(f RetryAfterHandler) DoWithBackoffOption
func WithDoWithBackoffOptionRoundTripper ¶
func WithDoWithBackoffOptionRoundTripper(rt http.RoundTripper) DoWithBackoffOption
WithDoWithBackoffOptionRoundTripper returns a DoWithBackoffOption.
func WithDoWithBackoffOptionTarget ¶ added in v1.2.21
func WithDoWithBackoffOptionTarget(target string) DoWithBackoffOption
WithDoWithBackoffOptionTarget returns a DoWithBackoffOption. TargetUrl is proxy's url, like socks5://127.0.0.1:8080 Host is proxy's addr, replace the HOST in TargetUrl if not empty
type DoWithBackoffOptionFunc ¶
type DoWithBackoffOptionFunc func(*doWithBackoff)
DoWithBackoffOptionFunc wraps a function that modifies doWithBackoff into an implementation of the DoWithBackoffOption interface.
type EmptyDoWithBackoffOption ¶
type EmptyDoWithBackoffOption struct{}
EmptyDoWithBackoffOption does not alter the configuration. It can be embedded in another structure to build custom options.
This API is EXPERIMENTAL.
type EmptyHandlerInterceptorChainOption ¶
type EmptyHandlerInterceptorChainOption struct{}
EmptyHandlerInterceptorChainOption does not alter the configuration. It can be embedded in another structure to build custom options.
This API is EXPERIMENTAL.
type EmptyRejectInsecureOption ¶
type EmptyRejectInsecureOption struct{}
EmptyRejectInsecureOption does not alter the configuration. It can be embedded in another structure to build custom options.
This API is EXPERIMENTAL.
type HandlerDecorator ¶ added in v1.2.11
HandlerDecorator is an interface representing the ability to decorate or wrap a http.Handler.
type HandlerDecorators ¶ added in v1.2.11
type HandlerDecorators []HandlerDecorator
HandlerDecorators defines a HandlerDecorator slice.
func (HandlerDecorators) WrapHandler ¶ added in v1.2.11
func (chain HandlerDecorators) WrapHandler(next http.Handler) http.Handler
type HandlerInterceptorChain ¶
type HandlerInterceptorChain struct {
// contains filtered or unexported fields
}
HandlerInterceptorChain interface that allows for customized handler execution chains. Applications can register any number of existing or custom interceptors for certain groups of handlers, to add common preprocessing behavior without needing to modify each handler implementation. A HandlerInterceptor gets called before the appropriate HandlerAdapter triggers the execution of the handler itself. This mechanism can be used for a large field of preprocessing aspects, e.g. for authorization checks, or common handler behavior like locale or theme changes. Its main purpose is to allow for factoring out repetitive handler code. https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/servlet/HandlerInterceptor.html
func NewHandlerInterceptorChain ¶
func NewHandlerInterceptorChain(opts ...HandlerInterceptorChainOption) *HandlerInterceptorChain
func (*HandlerInterceptorChain) ApplyOptions ¶
func (o *HandlerInterceptorChain) ApplyOptions(options ...HandlerInterceptorChainOption) *HandlerInterceptorChain
func (HandlerInterceptorChain) InjectHttpHandler ¶
func (chain HandlerInterceptorChain) InjectHttpHandler(next http.Handler) http.Handler
InjectHttpHandler returns a http handler injected by chain
type HandlerInterceptorChainOption ¶
type HandlerInterceptorChainOption interface {
// contains filtered or unexported methods
}
A HandlerInterceptorChainOption sets options.
func WithHandlerInterceptor ¶
func WithHandlerInterceptor( preHandle func(w http.ResponseWriter, r *http.Request) error, wrapHandle func(h http.Handler) http.Handler, postHandle func(w http.ResponseWriter, r *http.Request), afterCompletion func(w http.ResponseWriter, r *http.Request, err any), ) HandlerInterceptorChainOption
type HandlerInterceptorChainOptionFunc ¶
type HandlerInterceptorChainOptionFunc func(*HandlerInterceptorChain)
HandlerInterceptorChainOptionFunc wraps a function that modifies HandlerInterceptorChain into an implementation of the HandlerInterceptorChainOption interface.
type RejectInsecureOption ¶
type RejectInsecureOption interface {
// contains filtered or unexported methods
}
A RejectInsecureOption sets options.
func RejectInsecureWithAllowedTlsCidrs ¶
func RejectInsecureWithAllowedTlsCidrs(allowedTLSCIDRs []string) RejectInsecureOption
RejectInsecureWithAllowedTlsCidrs specifies whether to allow any request which client or proxy's ip included a cidr is a CIDR notation IP address and prefix length, like "192.0.2.0/24" or "2001:db8::/32", as defined in RFC 4632 and RFC 4291.
func RejectInsecureWithErrorLog ¶
func RejectInsecureWithErrorLog(l *log.Logger) RejectInsecureOption
RejectInsecureWithErrorLog specifies an optional logger for errors
func RejectInsecureWithForceHttp ¶
func RejectInsecureWithForceHttp(forceHttp bool) RejectInsecureOption
RejectInsecureWithForceHttp specifies whether to allow any request, as a shortcut circuit
func RejectInsecureWithWhitelistedPaths ¶
func RejectInsecureWithWhitelistedPaths(whitelistedPaths []string) RejectInsecureOption
RejectInsecureWithWhitelistedPaths specifies whether to allow any request which http path matches
type RejectInsecureOptionFunc ¶
type RejectInsecureOptionFunc func(*rejectInsecure)
RejectInsecureOptionFunc wraps a function that modifies rejectInsecure into an implementation of the RejectInsecureOption interface.
type RetryAfterHandler ¶
type RoundTripDecorator ¶ added in v1.2.11
type RoundTripDecorator interface {
WrapRoundTrip(rt http.RoundTripper) http.RoundTripper
}
RoundTripDecorator is an interface representing the ability to decorate or wrap a http.RoundTripper.
type RoundTripDecorators ¶ added in v1.2.11
type RoundTripDecorators []RoundTripDecorator
RoundTripDecorators defines a RoundTripDecorator slice.
func (RoundTripDecorators) WrapRoundTrip ¶ added in v1.2.11
func (chain RoundTripDecorators) WrapRoundTrip(next http.RoundTripper) http.RoundTripper
type RoundTripFunc ¶
RoundTripFunc is an adapter to allow the use of ordinary functions as HTTP Transport handlers. If f is a function with the appropriate signature, RoundTripFunc(f) is a Handler that calls f.
Source Files ¶
- backoff.go
- backoff.transport.go
- client.go
- clone.go
- content_range.go
- defaults.go
- dowithbackoff.options.go
- dowithbackoff_options.go
- fs.go
- handler.go
- handlerinterceptorchain.options.go
- handlerinterceptorchain_options.go
- interceptors.recover.client.go
- interceptors.recover.go
- interceptors.recover.server.go
- interceptors.reject.server.go
- interceptors.server.go
- interceptors.x-request-id.go
- method.go
- proxy.go
- range.go
- reject_insecure.option.go
- rejectinsecure_options.go
- request.go
- response_writer.go
- rewind.go
- roundtrip.go
- server.go
- transport.host.go
- transport.proxy.go
- warn.go