client

package
v1.70.2 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrResponseTooLarge = errors.New("response body truncated, it exceeds configured limit")

Functions

func NewHTTPClient

func NewHTTPClient(ctx context.Context, opts ...HTTPOption) *http.Client

NewHTTPClient creates a new HTTP client with the provided options. If no transport is specified, it defaults to otelhttp.NewTransport(http.DefaultTransport).

func NewLoggingTransport added in v1.65.7

func NewLoggingTransport(transport http.RoundTripper, opts ...LoggingTransportOption) http.RoundTripper

NewLoggingTransport creates a new logging HTTP transport. By default, it logs requests and responses but not headers or body for security.

func WrapClient added in v1.65.7

func WrapClient(client *http.Client, opts ...LoggingTransportOption) *http.Client

WrapClient wraps an existing HTTP client with logging transport.

Types

type HTTPOption

type HTTPOption func(*httpConfig)

HTTPOption configures HTTP client behavior. It can be used to configure timeout, transport, and other HTTP client settings.

func WithHTTPCheckRedirect

func WithHTTPCheckRedirect(checkRedirect func(req *http.Request, via []*http.Request) error) HTTPOption

WithHTTPCheckRedirect sets the redirect policy.

func WithHTTPClientCredentials added in v1.66.2

func WithHTTPClientCredentials(cfg *clientcredentials.Config) HTTPOption

WithHTTPClientCredentials the client credentials the client can utilize.

func WithHTTPCookieJar

func WithHTTPCookieJar(jar http.CookieJar) HTTPOption

WithHTTPCookieJar sets the cookie jar.

func WithHTTPEnableH2C added in v1.66.2

func WithHTTPEnableH2C() HTTPOption

WithHTTPEnableH2C sets the enable h2c option to active.

func WithHTTPIdleTimeout

func WithHTTPIdleTimeout(timeout time.Duration) HTTPOption

WithHTTPIdleTimeout sets the idle timeout.

func WithHTTPRetryPolicy added in v1.70.1

func WithHTTPRetryPolicy(retryPolicy *RetryPolicy) HTTPOption

WithHTTPRetryPolicy setts required retry policy.

func WithHTTPTimeout

func WithHTTPTimeout(timeout time.Duration) HTTPOption

WithHTTPTimeout sets the request timeout.

func WithHTTPTraceRequestHeaders added in v1.65.7

func WithHTTPTraceRequestHeaders() HTTPOption

WithHTTPTraceRequestHeaders enables or disables header logging.

func WithHTTPTraceRequests added in v1.65.7

func WithHTTPTraceRequests() HTTPOption

WithHTTPTraceRequests enables or disables request logging.

func WithHTTPTransport

func WithHTTPTransport(transport http.RoundTripper) HTTPOption

WithHTTPTransport sets the HTTP transport.

type InvokeResponse added in v1.70.1

type InvokeResponse struct {
	StatusCode int
	Headers    http.Header
	Body       io.ReadCloser
	// contains filtered or unexported fields
}

func (*InvokeResponse) Close added in v1.70.1

func (s *InvokeResponse) Close() error

func (*InvokeResponse) Decode added in v1.70.1

func (s *InvokeResponse) Decode(ctx context.Context, v any) error

Decode streams a JSON response directly into v without buffering the entire body. The response body is closed after decoding.

func (*InvokeResponse) ToContent added in v1.70.1

func (s *InvokeResponse) ToContent(ctx context.Context) ([]byte, error)

func (*InvokeResponse) ToFile added in v1.70.1

func (s *InvokeResponse) ToFile(ctx context.Context, writer io.Writer) (int64, error)

type LoggingTransportOption added in v1.65.7

type LoggingTransportOption func(*loggingTransport)

LoggingTransportOption configures the logging HTTP transport.

func WithTransportLogBody added in v1.65.7

func WithTransportLogBody(enabled bool) LoggingTransportOption

WithTransportLogBody enables or disables body logging. Note: Be careful when enabling this as bodies may contain sensitive information or be large.

func WithTransportLogHeaders added in v1.65.7

func WithTransportLogHeaders(enabled bool) LoggingTransportOption

WithTransportLogHeaders enables or disables header logging. Note: Be careful when enabling this as headers may contain sensitive information.

func WithTransportLogRequests added in v1.65.7

func WithTransportLogRequests(enabled bool) LoggingTransportOption

WithTransportLogRequests enables or disables request logging.

func WithTransportLogResponses added in v1.65.7

func WithTransportLogResponses(enabled bool) LoggingTransportOption

WithTransportLogResponses enables or disables response logging.

func WithTransportMaxBodySize added in v1.65.7

func WithTransportMaxBodySize(size int64) LoggingTransportOption

WithTransportMaxBodySize sets the maximum body size to log.

type Manager added in v1.63.0

type Manager interface {
	Client(ctx context.Context) *http.Client
	SetClient(ctx context.Context, cl *http.Client)

	Invoke(ctx context.Context,
		method string, endpointURL string, payload any,
		headers http.Header, opts ...HTTPOption) (*InvokeResponse, error)
	InvokeWithURLEncoded(ctx context.Context,
		method string, endpointURL string, payload url.Values,
		headers http.Header, opts ...HTTPOption) (*InvokeResponse, error)
	InvokeStream(
		ctx context.Context,
		method string, endpointURL string,
		body io.Reader,
		headers http.Header,
		opts ...HTTPOption,
	) (*InvokeResponse, error)
}

func NewManager added in v1.63.0

func NewManager(ctx context.Context, opts ...HTTPOption) Manager

NewManager creates a new invoker with the provided options.

type RetryPolicy added in v1.70.1

type RetryPolicy struct {
	MaxAttempts int
	Backoff     func(attempt int) time.Duration
}

Jump to

Keyboard shortcuts

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