httpclient

package
v0.42.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: Apache-2.0 Imports: 28 Imported by: 3

Documentation

Index

Constants

View Source
const JWTGrantType = "urn:ietf:params:oauth:grant-type:jwt-bearer"
View Source
const UrlEncodedContentType = "application/x-www-form-urlencoded"

Variables

This section is empty.

Functions

func DefaultErrorMapper

func DefaultErrorMapper(ctx context.Context, resp common.ResponseWrapper) error

DefaultErrorMapper returns *HttpError

func DefaultErrorRetriable

func DefaultErrorRetriable(ctx context.Context, err error) bool

func EncodeMultiSegmentPathParameter added in v0.37.0

func EncodeMultiSegmentPathParameter(p string) string

Types

type ApiClient

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

func NewApiClient

func NewApiClient(cfg ClientConfig) *ApiClient

func (*ApiClient) Do

func (c *ApiClient) Do(ctx context.Context, method, path string, opts ...DoOption) error

Do sends an HTTP request against path.

func (*ApiClient) GetOAuthToken added in v0.41.0

func (c *ApiClient) GetOAuthToken(ctx context.Context, authDetails string, token *oauth2.Token) (*credentials.OAuthToken, error)

Returns a new OAuth token using the provided token. The token must be a JWT token. The resulting token is scoped to the authorization details provided.

**NOTE:** Experimental: This API may change or be removed in a future release without warning.

func (*ApiClient) InContextForOAuth2

func (c *ApiClient) InContextForOAuth2(ctx context.Context) context.Context

InContextForOAuth2 returns a context with a custom *http.Client to be used for only for token acquisition through golang.org/x/oauth2 package

func (*ApiClient) RoundTrip

func (c *ApiClient) RoundTrip(request *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper to integrate with golang.org/x/oauth2

type ClientConfig

type ClientConfig struct {
	AuthVisitor RequestVisitor
	Visitors    []RequestVisitor

	RetryTimeout       time.Duration
	HTTPTimeout        time.Duration
	InsecureSkipVerify bool
	DebugHeaders       bool
	DebugTruncateBytes int
	RateLimitPerSecond int

	ErrorMapper     func(ctx context.Context, resp common.ResponseWrapper) error
	ErrorRetriable  func(ctx context.Context, err error) bool
	TransientErrors []string

	Transport http.RoundTripper
}

type DoOption

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

func WithRequestData

func WithRequestData(body any) DoOption

WithRequestData takes either a struct instance, map, string, bytes, or io.Reader and sends it either as query string for GET and DELETE calls, or as request body for POST, PUT, and PATCH calls.

Experimental: this method may eventually be split into more granular options.

func WithRequestHeader

func WithRequestHeader(k, v string) DoOption

WithRequestHeader adds a request visitor, that sets a header on a request

func WithRequestHeaders

func WithRequestHeaders(headers map[string]string) DoOption

WithRequestHeaders adds a request visitor, that set all headers from a map

func WithRequestVisitor

func WithRequestVisitor(visitor func(r *http.Request) error) DoOption

WithRequestVisitor applies given function on a request

func WithResponseHeader

func WithResponseHeader(key string, value *string) DoOption

func WithResponseUnmarshal

func WithResponseUnmarshal(response any) DoOption

func WithTokenSource

func WithTokenSource(ts oauth2.TokenSource) DoOption

WithTokenSource uses the specified golang.org/x/oauth2 token source on a request

func WithUrlEncodedData added in v0.41.0

func WithUrlEncodedData(body any) DoOption

WithUrlEncodedData takes either a struct instance, map, string, bytes, or io.Reader plus a content type, and sends it either as query string for GET and DELETE calls, or as request body for POST, PUT, and PATCH calls. The content type is set to "application/x-www-form-urlencoded" and the body is encoded as a query string.

Experimental: this method may eventually be split into more granular options.

type GetOAuthTokenRequest added in v0.41.0

type GetOAuthTokenRequest struct {
	// Defines the method used to get the token.
	GrantType string `url:"grant_type"`
	// An array of authorization details that the token should be scoped to. This needs to be passed in string format.
	AuthorizationDetails string `url:"authorization_details"`
	// The token that will be exchanged for an OAuth token.
	Assertion string `url:"assertion"`
}

GetOAuthTokenRequest is the request to get an OAuth token. It follows the OAuth 2.0 Rich Authorization Requests specification. https://datatracker.ietf.org/doc/html/rfc9396

type HttpError

type HttpError struct {
	*http.Response
	Message string
	// contains filtered or unexported fields
}

func (*HttpError) Error

func (r *HttpError) Error() string

func (*HttpError) Unwrap

func (r *HttpError) Unwrap() error

type RequestVisitor

type RequestVisitor func(*http.Request) error

type TimeoutTicker added in v0.34.0

type TimeoutTicker interface {
	Tick()
	Cancel()
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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