http

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package http implements the HTTP transport protocol.

Index

Constants

This section is empty.

Variables

View Source
var (

	// DefaultClient is the default HTTP client, which uses a net/http client configured
	// with http.DefaultTransport.
	DefaultClient = NewClient(nil)
)

Functions

func NewClient

func NewClient(c *http.Client) transport.Transport

NewClient creates a new client with a custom net/http client. See `InstallProtocol` to install and override default http client. If the net/http client is nil or empty, it will use a net/http client configured with http.DefaultTransport.

Note that for HTTP client cannot distinguish between private repositories and unexistent repositories on GitHub. So it returns `ErrAuthorizationRequired` for both.

func NewClientWithOptions

func NewClientWithOptions(c *http.Client, opts *ClientOptions) transport.Transport

NewClientWithOptions returns a new client configured with the provided net/http client and other custom options specific to the client. If the net/http client is nil or empty, it will use a net/http client configured with http.DefaultTransport.

func NewErr

func NewErr(r *http.Response) error

NewErr returns a new Err based on a http response

Types

type AuthMethod

type AuthMethod interface {
	transport.AuthMethod
	SetAuth(r *http.Request)
}

AuthMethod is concrete implementation of common.AuthMethod for HTTP services

type BasicAuth

type BasicAuth struct {
	Username, Password string
}

BasicAuth represent a HTTP basic auth

func (*BasicAuth) Name

func (a *BasicAuth) Name() string

Name is name of the auth

func (*BasicAuth) SetAuth

func (a *BasicAuth) SetAuth(r *http.Request)

func (*BasicAuth) String

func (a *BasicAuth) String() string

type ClientOptions

type ClientOptions struct {
	// CacheMaxEntries is the max no. of entries that the transport objects
	// cache will hold at any given point of time. It must be a positive integer.
	// Calling `client.addTransport()` after the cache has reached the specified
	// size, will result in the least recently used transport getting deleted
	// before the provided transport is added to the cache.
	CacheMaxEntries int
}

ClientOptions holds user configurable options for the client.

type Err

type Err struct {
	Response *http.Response
}

Err is a dedicated error to return errors based on status code

func (*Err) Error

func (e *Err) Error() string

func (*Err) StatusCode

func (e *Err) StatusCode() int

StatusCode returns the status code of the response

type TokenAuth

type TokenAuth struct {
	Token string
}

TokenAuth implements an http.AuthMethod that can be used with http transport to authenticate with HTTP token authentication (also known as bearer authentication).

IMPORTANT: If you are looking to use OAuth tokens with popular servers (e.g. GitHub, Bitbucket, GitLab) you should use BasicAuth instead. These servers use basic HTTP authentication, with the OAuth token as user or password. Check the documentation of your git server for details.

func (*TokenAuth) Name

func (a *TokenAuth) Name() string

Name is name of the auth

func (*TokenAuth) SetAuth

func (a *TokenAuth) SetAuth(r *http.Request)

func (*TokenAuth) String

func (a *TokenAuth) String() string

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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