http
v0.0.0-20201019013536-69ae1d429836
Documentation
pkg.go.dev ↗Variables
OutgoingAccessAllowed
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
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."
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.
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."
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
Client
type Client struct {
HTTPClient
// contains filtered or unexported fields
}
Client represents an http client.
NewClient
func NewClient(cfg Config) *Client
NewClient returns a new juju http client defined by the given config.
Client.Client
func (c *Client) Client() *http.Client
Client returns the underlying http.Client. Used in testing only.
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.
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.
HTTPClient
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
HTTPClient represents an http.Client.
Logger
type Logger interface {
IsTraceEnabled() bool
Tracef(message string, args ...interface{})
}
Logger represents methods required for package logging.