Package httptransport provides functionality for managing HTTP client connections to Google Cloud services.
Functions
func AddAuthorizationMiddleware
func
AddAuthorizationMiddleware
(
client
*
http
.
Client
,
creds
*
auth
.
Credentials
)
error
AddAuthorizationMiddleware adds a middleware to the provided client's transport that sets the Authorization header with the value produced by the provided [cloud.google.com/go/auth.Credentials]. An error is returned only if client or creds is nil.
func NewClient
NewClient returns a [net/http.Client] that can be used to communicate with a Google cloud service, configured with the provided [Options]. It automatically appends Authorization headers to all outgoing requests.
func SetAuthHeader
SetAuthHeader uses the provided token to set the Authorization header on a request. If the token.Type is empty, the type is assumed to be Bearer.
ClientCertProvider
type
ClientCertProvider
=
func
(
*
tls
.
CertificateRequestInfo
)
(
*
tls
.
Certificate
,
error
)
ClientCertProvider is a function that returns a TLS client certificate to be used when opening TLS connections. It follows the same semantics as [crypto/tls.Config.GetClientCertificate].
InternalOptions
type
InternalOptions
struct
{
// EnableJWTWithScope specifies if scope can be used with self-signed JWT.
EnableJWTWithScope
bool
// DefaultAudience specifies a default audience to be used as the audience
// field ("aud") for the JWT token authentication.
DefaultAudience
string
// DefaultEndpointTemplate combined with UniverseDomain specifies the
// default endpoint.
DefaultEndpointTemplate
string
// DefaultMTLSEndpoint specifies the default mTLS endpoint.
DefaultMTLSEndpoint
string
// DefaultScopes specifies the default OAuth2 scopes to be used for a
// service.
DefaultScopes
[]
string
// SkipValidation bypasses validation on Options. It should only be used
// internally for clients that needs more control over their transport.
SkipValidation
bool
}
InternalOptions are only meant to be set by generated client code. These are not meant to be set directly by consumers of this package. Configuration in this type is considered EXPERIMENTAL and may be removed at any time in the future without warning.
Options
type
Options
struct
{
// DisableTelemetry disables default telemetry (OpenTelemetry). An example
// reason to do so would be to bind custom telemetry that overrides the
// defaults.
DisableTelemetry
bool
// DisableAuthentication specifies that no authentication should be used. It
// is suitable only for testing and for accessing public resources, like
// public Google Cloud Storage buckets.
DisableAuthentication
bool
// Headers are extra HTTP headers that will be appended to every outgoing
// request.
Headers
http
.
Header
// BaseRoundTripper overrides the base transport used for serving requests.
// If specified ClientCertProvider is ignored.
BaseRoundTripper
http
.
RoundTripper
// Endpoint overrides the default endpoint to be used for a service.
Endpoint
string
// APIKey specifies an API key to be used as the basis for authentication.
// If set DetectOpts are ignored.
APIKey
string
// Credentials used to add Authorization header to all requests. If set
// DetectOpts are ignored.
Credentials
*
auth
.
Credentials
// ClientCertProvider is a function that returns a TLS client certificate to
// be used when opening TLS connections. It follows the same semantics as
// crypto/tls.Config.GetClientCertificate.
ClientCertProvider
ClientCertProvider
// DetectOpts configures settings for detect Application Default
// Credentials.
DetectOpts
*
detect
.
DetectOptions
// UniverseDomain is the default service domain for a given Cloud universe.
// The default value is "googleapis.com". This is the universe domain
// configured for the client, which will be compared to the universe domain
// that is separately configured for the credentials.
UniverseDomain
string
// InternalOptions are NOT meant to be set directly by consumers of this
// package, they should only be set by generated client code.
InternalOptions
*
InternalOptions
}
Options used to configure a [net/http.Client] from [NewClient].