httpclient

package
v4.25.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthFieldSpecs added in v4.12.0

func AuthFieldSpecs() []*service.ConfigField

AuthFieldSpecs returns a map of field specs for an auth type.

func AuthFieldSpecsExpanded added in v4.12.0

func AuthFieldSpecsExpanded() []*service.ConfigField

AuthFieldSpecsExpanded includes OAuth2 and JWT fields that might not be appropriate for all components.

func BasicAuthField added in v4.12.0

func BasicAuthField() *service.ConfigField

BasicAuthField returns a config field spec for basic authentication.

func ConfigField added in v4.12.0

func ConfigField(defaultVerb string, forOutput bool, extraChildren ...*service.ConfigField) *service.ConfigField

ConfigField returns a public API config field spec for an HTTP component, with optional extra fields added to the end.

Types

type AuthConfig added in v4.12.0

type AuthConfig struct {
	OAuth     OAuthConfig
	BasicAuth BasicAuthConfig
	JWT       JWTConfig
}

AuthConfig contains configuration params for various HTTP auth strategies.

func NewAuthConfig added in v4.12.0

func NewAuthConfig() AuthConfig

NewAuthConfig creates a new Config with default values.

func (AuthConfig) Sign added in v4.12.0

func (c AuthConfig) Sign(f fs.FS, req *http.Request) error

Sign method to sign an HTTP request for configured auth strategies.

type BasicAuthConfig added in v4.12.0

type BasicAuthConfig struct {
	Enabled  bool
	Username string
	Password string
}

BasicAuthConfig contains fields for setting basic authentication in HTTP requests.

func NewBasicAuthConfig added in v4.12.0

func NewBasicAuthConfig() BasicAuthConfig

NewBasicAuthConfig returns a default configuration for basic authentication in HTTP client requests.

func (BasicAuthConfig) Sign added in v4.12.0

func (basic BasicAuthConfig) Sign(req *http.Request) error

Sign method to sign an HTTP request for an OAuth exchange.

type Client

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

Client is a component able to send and receive Benthos messages over HTTP.

func NewClientFromOldConfig

func NewClientFromOldConfig(conf OldConfig, mgr *service.Resources, opts ...RequestOpt) (*Client, error)

NewClientFromOldConfig creates a new request creator from an old struct style config. Eventually I'd like to phase these out for the more dynamic service style parses, but it'll take a while so we have this for now.

func (*Client) Close

func (h *Client) Close(ctx context.Context) error

Close the client.

func (*Client) ResponseToBatch

func (h *Client) ResponseToBatch(res *http.Response) (service.MessageBatch, error)

ResponseToBatch attempts to parse an HTTP response into a 2D slice of bytes.

func (*Client) Send

Send creates an HTTP request from the client config, a provided message to be sent as the body of the request, and a reference message used to establish interpolated fields for the request (which can be the same as the message used for the body).

If the request is successful then the response is parsed into a message, including headers added as metadata (when configured to do so).

func (*Client) SendToResponse

func (h *Client) SendToResponse(ctx context.Context, sendMsg service.MessageBatch) (res *http.Response, err error)

SendToResponse attempts to create an HTTP request from a provided message, performs it, and then returns the *http.Response, allowing the raw response to be consumed.

type JWTConfig added in v4.12.0

type JWTConfig struct {
	Enabled        bool
	Claims         jwt.MapClaims
	Headers        map[string]any
	SigningMethod  string
	PrivateKeyFile string
	// contains filtered or unexported fields
}

JWTConfig holds the configuration parameters for an JWT exchange.

func NewJWTConfig added in v4.12.0

func NewJWTConfig() JWTConfig

NewJWTConfig returns a new JWTConfig with default values.

func (JWTConfig) Sign added in v4.12.0

func (j JWTConfig) Sign(f fs.FS, req *http.Request) error

Sign method to sign an HTTP request for an JWT exchange.

type MultipartExpressions

type MultipartExpressions struct {
	ContentDisposition *service.InterpolatedString
	ContentType        *service.InterpolatedString
	Body               *service.InterpolatedString
}

MultipartExpressions represents three dynamic expressions that define a multipart message part in an HTTP request. Specifying one or more of these can be used as a way of creating HTTP requests that overrides the default behaviour.

type OAuth2Config added in v4.12.0

type OAuth2Config struct {
	Enabled        bool
	ClientKey      string
	ClientSecret   string
	TokenURL       string
	Scopes         []string
	EndpointParams map[string][]string
}

OAuth2Config holds the configuration parameters for an OAuth2 exchange.

func NewOAuth2Config added in v4.12.0

func NewOAuth2Config() OAuth2Config

NewOAuth2Config returns a new OAuth2Config with default values.

func (OAuth2Config) Client added in v4.12.0

func (oauth OAuth2Config) Client(ctx context.Context, base *http.Client) *http.Client

Client returns an http.Client with OAuth2 configured.

type OAuthConfig added in v4.12.0

type OAuthConfig struct {
	Enabled           bool
	ConsumerKey       string
	ConsumerSecret    string
	AccessToken       string
	AccessTokenSecret string
}

OAuthConfig holds the configuration parameters for an OAuth exchange.

func NewOAuthConfig added in v4.12.0

func NewOAuthConfig() OAuthConfig

NewOAuthConfig returns a new OAuthConfig with default values.

func (OAuthConfig) Sign added in v4.12.0

func (oauth OAuthConfig) Sign(req *http.Request) error

Sign method to sign an HTTP request for an OAuth exchange.

type OldConfig added in v4.12.0

type OldConfig struct {
	URL                 *service.InterpolatedString
	Verb                string
	Headers             map[string]*service.InterpolatedString
	Metadata            *service.MetadataFilter
	ExtractMetadata     *service.MetadataFilter
	RateLimit           string
	Timeout             time.Duration
	Retry               time.Duration
	MaxBackoff          time.Duration
	NumRetries          int
	BackoffOn           []int
	DropOn              []int
	SuccessfulOn        []int
	DumpRequestLogLevel string
	TLSEnabled          bool
	TLSConf             *tls.Config
	ProxyURL            string
	Auth                AuthConfig
	OAuth2              OAuth2Config
}

OldConfig is a configuration struct for an HTTP client.

func ConfigFromParsed added in v4.25.0

func ConfigFromParsed(pConf *service.ParsedConfig) (conf OldConfig, err error)

ConfigFromParsed attempts to parse an http client config struct from a parsed plugin config.

type RequestCreator

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

RequestCreator creates *http.Request types from messages based on various configurable parameters.

func RequestCreatorFromOldConfig

func RequestCreatorFromOldConfig(conf OldConfig, mgr *service.Resources, opts ...RequestOpt) (*RequestCreator, error)

RequestCreatorFromOldConfig creates a new request creator from an old struct style config. Eventually I'd like to phase these out for the more dynamic service style parses, but it'll take a while so we have this for now.

func (*RequestCreator) Create

func (r *RequestCreator) Create(refBatch service.MessageBatch) (req *http.Request, err error)

Create an *http.Request using a reference message batch to extract the body and headers of the request. It's possible that the creator has been given explicit overrides for the body, in which case the reference batch is only used for general request headers/metadata enrichment.

type RequestOpt

type RequestOpt func(r *RequestCreator)

RequestOpt represents a customisation of a request creator.

func WithExplicitBody

func WithExplicitBody(e *service.InterpolatedString) RequestOpt

WithExplicitBody modifies the request creator to instead only use input reference messages for headers and metadata, and use the expression for creating a body.

func WithExplicitMultipart

func WithExplicitMultipart(m []MultipartExpressions) RequestOpt

WithExplicitMultipart modifies the request creator to instead only use input reference messages for headers and metadata, and use a list of multipart expressions for creating a body.

type RequestSigner

type RequestSigner func(f fs.FS, req *http.Request) error

RequestSigner is a closure configured to enrich requests with various functions, usually authentication.

func AuthSignerFromParsed

func AuthSignerFromParsed(conf *service.ParsedConfig) (RequestSigner, error)

AuthSignerFromParsed takes a parsed config which is expected to contain fields from AuthFields, and returns a RequestSigner that implements the configured authentication strategies by enriching a request directly.

Jump to

Keyboard shortcuts

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