request

package
v4.43.3 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2022 License: MIT Imports: 18 Imported by: 30

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoRedirection = func(*http.Request, []*http.Request) error {
	return http.ErrUseLastResponse
}

NoRedirection discard redirection

Functions

func AddSignature added in v4.20.0

func AddSignature(r *http.Request, keyID string, secret, payload []byte)

AddSignature add Authorization header based on content signature based on https://datatracker.ietf.org/doc/html/draft-cavage-http-signatures-12

func AddTracerToDefaultClient added in v4.36.0

func AddTracerToDefaultClient(tracerProvider trace.TracerProvider)

AddTracerToDefaultClient change default client

func CreateClient added in v4.28.1

func CreateClient(timeout time.Duration, onRedirect func(*http.Request, []*http.Request) error) *http.Client

CreateClient creates http client with given timeout and redirection handling

func DiscardBody added in v4.22.3

func DiscardBody(body io.ReadCloser) error

DiscardBody of a response

func Do

func Do(req *http.Request) (*http.Response, error)

Do send request with default client

func DoWithClient

func DoWithClient(client *http.Client, req *http.Request) (*http.Response, error)

DoWithClient send request with given client

func ReadBodyRequest

func ReadBodyRequest(r *http.Request) ([]byte, error)

ReadBodyRequest return content of a body request (defined as a ReadCloser)

func ReadBodyResponse

func ReadBodyResponse(r *http.Response) ([]byte, error)

ReadBodyResponse return content of a body response (defined as a ReadCloser)

func ValidateSignature added in v4.20.0

func ValidateSignature(r *http.Request, secret []byte) (bool, error)

ValidateSignature check Authorization header based on content based on https://datatracker.ietf.org/doc/html/draft-cavage-http-signatures-12

Types

type Request

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

Request describe a complete request

func Delete added in v4.33.0

func Delete(url string) Request

Delete create DELETE to given url

func Get added in v4.33.0

func Get(url string) Request

Get create GET to given url

func New

func New() Request

New create a new Request

func Patch added in v4.33.0

func Patch(url string) Request

Patch create PATCH to given url

func Post added in v4.33.0

func Post(url string) Request

Post create POST to given url

func Put added in v4.33.0

func Put(url string) Request

Put create PUT to given url

func (Request) Accept added in v4.39.2

func (r Request) Accept(accept string) Request

Accept set Accept header

func (Request) AcceptJSON added in v4.39.2

func (r Request) AcceptJSON() Request

AcceptJSON set Accept header to application/json

func (Request) BasicAuth

func (r Request) BasicAuth(username, password string) Request

BasicAuth add Basic Auth header

func (Request) Build

func (r Request) Build(ctx context.Context, payload io.ReadCloser) (*http.Request, error)

Build create request for given context and payload

func (Request) ContentForm

func (r Request) ContentForm() Request

ContentForm set Content-Type header to application/x-www-form-urlencoded

func (Request) ContentJSON

func (r Request) ContentJSON() Request

ContentJSON set Content-Type header to application/json

func (Request) ContentType

func (r Request) ContentType(contentType string) Request

ContentType set Content-Type header

func (Request) Delete

func (r Request) Delete(url string) Request

Delete set DELETE to given url

func (Request) Form

func (r Request) Form(ctx context.Context, data url.Values) (*http.Response, error)

Form send request with given context and url.Values as payload

func (Request) Get

func (r Request) Get(url string) Request

Get set GET to given url

func (Request) Header

func (r Request) Header(name, value string) Request

Header add header to request

func (Request) IsZero added in v4.22.2

func (r Request) IsZero() bool

IsZero checks if instance is valued

func (Request) JSON

func (r Request) JSON(ctx context.Context, body any) (*http.Response, error)

JSON send request with given context and given interface as JSON payload

func (Request) Method

func (r Request) Method(method string) Request

Method set method of Request

func (Request) MethodURL added in v4.37.2

func (r Request) MethodURL(method, url string) Request

MethodURL set method and URL of Request

func (Request) Multipart added in v4.40.0

func (r Request) Multipart(ctx context.Context, feed func(mw *multipart.Writer) error) (*http.Response, error)

Multipart send request with given context and given interface as multipart content

func (Request) Patch

func (r Request) Patch(url string) Request

Patch set PATCH to given url

func (Request) Path added in v4.22.2

func (r Request) Path(path string) Request

Path appends given path to the current URL

func (Request) Post

func (r Request) Post(url string) Request

Post set POST to given url

func (Request) Put

func (r Request) Put(url string) Request

Put set PUT to given url

func (Request) Send

func (r Request) Send(ctx context.Context, payload io.ReadCloser) (*http.Response, error)

Send build request and send it with defined client

func (Request) StreamJSON added in v4.39.2

func (r Request) StreamJSON(ctx context.Context, body any) (*http.Response, error)

StreamJSON send request with given context and given interface as JSON stream

func (Request) String added in v4.23.0

func (r Request) String() string

String representation of the request

func (Request) URL

func (r Request) URL(url string) Request

URL set URL of Request

func (Request) WithClient

func (r Request) WithClient(client *http.Client) Request

WithClient defines net/http client to use, instead of default one (15sec timeout and no redirect)

func (Request) WithSignatureAuthorization added in v4.20.0

func (r Request) WithSignatureAuthorization(keyID string, secret []byte) Request

WithSignatureAuthorization add Authorization header when sending request by calculating digest and HMAC signature header

Jump to

Keyboard shortcuts

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