http

package
v3.0.0-alpha.6 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultContentType = "application/json"

Variables

This section is empty.

Functions

func IsResponseRedirect

func IsResponseRedirect(statusCode int) bool

func IsStatusIn

func IsStatusIn(statusCode int, statuses ...int) bool

func IsStatusSuccess

func IsStatusSuccess(statusCode int) bool

Types

type ClientProvider

type ClientProvider interface {
	// Client returns a *http.Client
	Client(ctx context.Context, followRedirects bool) (*http.Client, error)

	// ReAuthenticate tells the provider to re-initialize the auth context
	ReAuthenticate(ctx context.Context) error
}

type Executor

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

Executor handles executing HTTP requests

func NewExecutor

func NewExecutor(clientProvider ClientProvider, apiAddress, userAgent string) *Executor

NewExecutor creates a new HTTP Executor instance

func (*Executor) ExecuteRequest

func (c *Executor) ExecuteRequest(request *Request) (*http.Response, error)

ExecuteRequest executes the specified request using the http.Client provided by the client provider

type OAuthSessionManager

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

OAuthSessionManager creates and manages OAuth http client instances

func NewOAuthSessionManager

func NewOAuthSessionManager(config *config.Config) *OAuthSessionManager

NewOAuthSessionManager creates a new OAuth session manager

func (*OAuthSessionManager) AccessToken

func (m *OAuthSessionManager) AccessToken(ctx context.Context) (string, error)

AccessToken returns the raw OAuth access token

func (*OAuthSessionManager) Client

func (m *OAuthSessionManager) Client(ctx context.Context, followRedirects bool) (*http.Client, error)

Client returns an authenticated OAuth http client

func (*OAuthSessionManager) ReAuthenticate

func (m *OAuthSessionManager) ReAuthenticate(ctx context.Context) error

ReAuthenticate causes a new http.Client to be created with new a new authentication context, likely in response to a 401

This won't work for userTokenAuth since we have no credentials to exchange for a new token.

type Request

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

Request is used to help build up an HTTP request

func NewRequest

func NewRequest(ctx context.Context, method, pathAndQuery string) *Request

NewRequest creates a new minimally configured HTTP request instance

func (*Request) WithBody

func (r *Request) WithBody(body io.Reader) *Request

WithBody adds the specified body as-is to the request and defaults the content type to JSON

func (*Request) WithContentLength

func (r *Request) WithContentLength(len int64) *Request

WithContentLength sets the content length, needed for file uploads

func (*Request) WithContentType

func (r *Request) WithContentType(contentType string) *Request

WithContentType sets the content type of the request body

func (*Request) WithFollowRedirects

func (r *Request) WithFollowRedirects(follow bool) *Request

WithFollowRedirects sets the content type of the request body

func (*Request) WithHeader

func (r *Request) WithHeader(name, value string) *Request

WithHeader sets an arbitrary header on the request

func (*Request) WithObject

func (r *Request) WithObject(obj any) *Request

WithObject adds an object to the request body to be JSON serialized

type UnauthenticatedClientProvider

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

func NewUnauthenticatedClientProvider

func NewUnauthenticatedClientProvider(httpClient *http.Client) *UnauthenticatedClientProvider

func (*UnauthenticatedClientProvider) Client

func (c *UnauthenticatedClientProvider) Client(ctx context.Context, followRedirects bool) (*http.Client, error)

func (*UnauthenticatedClientProvider) ReAuthenticate

func (c *UnauthenticatedClientProvider) ReAuthenticate(ctx context.Context) error

Jump to

Keyboard shortcuts

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