http

package module
v0.0.0-...-69ae1d4 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2020 License: AGPL-3.0 Imports: 15 Imported by: 0

README

http

Juju wrapper for the standard go HTTP library.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OutgoingAccessAllowed = true

OutgoingAccessAllowed determines whether connections other than localhost can be dialled. Used for testing via the juju conn suite and the base suite.

Functions

func BasicAuthHeader

func BasicAuthHeader(username, password string) http.Header

BasicAuthHeader creates a header that contains just the "Authorization" entry. The implementation was originally taked from net/http but this is needed externally from the http request object in order to use this with our websockets. See 2 (end of page 4) http://www.ietf.org/rfc/rfc2617.txt "To receive authorization, the client sends the userid and password, separated by a single colon (":") character, within a base64 encoded string in the credentials."

func NewHttpTLSTransport

func NewHttpTLSTransport(tlsConfig *tls.Config) *http.Transport

NewHttpTLSTransport returns a new http.Transport constructed with the TLS config and the necessary parameters for Juju.

func ParseBasicAuthHeader

func ParseBasicAuthHeader(h http.Header) (userid, password string, err error)

ParseBasicAuth attempts to find an Authorization header in the supplied http.Header and if found parses it as a Basic header. See 2 (end of page 4) http://www.ietf.org/rfc/rfc2617.txt "To receive authorization, the client sends the userid and password, separated by a single colon (":") character, within a base64 encoded string in the credentials."

func SecureTLSConfig

func SecureTLSConfig() *tls.Config

SecureTLSConfig returns a tls.Config that conforms to Juju's security standards, so as to avoid known security vulnerabilities in certain configurations.

Currently it excludes RC4 implementations from the available ciphersuites, requires ciphersuites that provide forward secrecy, and sets the minimum TLS version to 1.2.

Types

type Client

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

Client represents an http client.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a new juju http client defined by the given config.

func (*Client) Client

func (c *Client) Client() *http.Client

Client returns the underlying http.Client. Used in testing only.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string) (resp *http.Response, err error)

Get issues a GET to the specified URL. It mimics the net/http Get, but allows for enhanced debugging.

When err is nil, resp always contains a non-nil resp.Body. Caller should close resp.Body when done reading from it.

type Config

type Config struct {
	// CACertificates contains an optional list of Certificate
	// Authority certificates to be used to validate certificates
	// of cloud infrastructure components.
	// The contents are Base64 encoded x.509 certs.
	CACertificates []string

	// Jar specifies the cookie jar.
	//
	// The Jar is used to insert relevant cookies into every
	// outbound Request and is updated with the cookie values
	// of every inbound Response. The Jar is consulted for every
	// redirect that the Client follows.
	//
	// If Jar is nil, cookies are only sent if they are explicitly
	// set on the Request.
	Jar http.CookieJar

	// SkipHostnameVerification indicates whether to use self-signed credentials
	// and not try to verify the hostname on the TLS/SSL certificates.
	SkipHostnameVerification bool

	// Logger is used to provide logging with the provided Client.
	// When logging level is set to Trace, the httptrace package is
	// used to log details about any Get done.  If empty, a local
	// logger is created.
	Logger Logger
}

Config holds configuration for creating a new http client.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient represents an http.Client.

type Logger

type Logger interface {
	IsTraceEnabled() bool
	Tracef(message string, args ...interface{})
}

Logger represents methods required for package logging.

Jump to

Keyboard shortcuts

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