httpclient

package
v4.11.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthFields

func AuthFields() []*service.ConfigField

AuthFields returns a list of config field specs for all basic, header based, HTTP authentication types. The configuration of these fields is possible to implement by enriching HTTP requests and does not interfere with the client.

func OldAuthFieldSpecs

func OldAuthFieldSpecs() docs.FieldSpecs

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

func OldAuthFieldSpecsExpanded

func OldAuthFieldSpecsExpanded() docs.FieldSpecs

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

func OldBasicAuthFieldSpec

func OldBasicAuthFieldSpec() docs.FieldSpec

OldBasicAuthFieldSpec returns a basic authentication field spec.

func OldFieldSpec

func OldFieldSpec(forOutput bool, extraChildren ...docs.FieldSpec) docs.FieldSpec

OldFieldSpec returns a field spec for an http client component.

Types

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.OldConfig, mgr bundle.NewManagement, 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) (resMsg message.Batch, err error)

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

func (*Client) Send

func (h *Client) Send(ctx context.Context, sendMsg message.Batch) (message.Batch, error)

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 message.Batch) (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 MultipartExpressions

type MultipartExpressions struct {
	ContentDisposition *field.Expression
	ContentType        *field.Expression
	Body               *field.Expression
}

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 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.OldConfig, mgr bundle.NewManagement, 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 message.Batch) (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 *field.Expression) 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 ifs.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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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