http

package
v1.67.3 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Copyright 2020 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Copyright 2022 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	LicenseHeader       = "X-License-Key"
	EntityKeyHeader     = "X-NRI-Entity-Key" // populated with the agent-id for the backend deny mechanism
	AgentEntityIdHeader = "X-NRI-Agent-Entity-Id"

	TrialStatusHeader = "X-Trial-Status"
	TrialStarting     = "starting"

	ClientTimeout = 30 * time.Second
)

HTTP default values

View Source
const (
	LOCALHOST           = "localhost"
	LOCALHOST_IPV6      = "::1"
	LOCALHOST_PREFIX_IP = "127."
)

Variables

View Source
var ErrEmptyStack = errors.New("Empty stack")
View Source
var ErrUnexepectedResponseCode = errors.New("endpoint returned and unexpected response code")
View Source
var NullHttpClient = func(req *http.Request) (res *http.Response, err error) {
	_, _ = ioutil.ReadAll(req.Body)
	defer req.Body.Close()
	return
}

NullHttpClient client discarding all the requests and returning empty objects.

Functions

func BuildTransport

func BuildTransport(cfg *config.Config, timeout time.Duration) http.RoundTripper

BuildTransport creates an http.Transport. If there is a configured proxy, in the configuration and environment, it configures the transport to use the proxy, according to the following priorities (from larger to lower priority):

1. HTTPS_PROXY env var 2. NRIA_PROXY env var / proxy config option 3. HTTP_PROXY env var

If the configuration option ignore_system_proxy is set, it ignores the HTTPS_PROXY and HTTP_PROXY configuration If the configuration option proxy_validate_certificates is set, it will force the HTTPS proxy options to verify the certificates

func CheckEndpointHealthiness added in v1.67.3

func CheckEndpointHealthiness(
	ctx context.Context,
	endpointURL string,
	license string,
	userAgent string,
	agentID string,
	timeout time.Duration,
	transport http.RoundTripper,
) (bool, error)

func CheckEndpointReachability

func CheckEndpointReachability(
	ctx context.Context,
	logger log.Entry,
	endpointURL string,
	license string,
	userAgent string,
	agentID string,
	timeout time.Duration,
	transport http.RoundTripper,
) (bool, error)

func ContainsLocalhost

func ContainsLocalhost(value string) bool

ContainsLocalhost checks if the given value contains a reference a localhost hostname or ip

func GetHttpClient

func GetHttpClient(
	httpTimeout time.Duration,
	transport http.RoundTripper,
) *http.Client

func IsLocalhost

func IsLocalhost(value string) bool

IsLocalhost checks if the given value is equal to a localhost hostname or ip

func IsResponseError

func IsResponseError(resp *http.Response) bool

IsResponseError is a non successful backend response.

func IsResponseSuccess

func IsResponseSuccess(resp *http.Response) bool

IsResponseSuccess is a successful backend response

func NewRequestDecoratorTransport added in v1.67.3

func NewRequestDecoratorTransport(configurator config.Provider, transport http.RoundTripper) http.RoundTripper

NewRequestDecoratorTransport comes with ability to decorate http request objects.

func ReplaceLocalhost

func ReplaceLocalhost(source, with string) string

ReplaceLocalhost replaces the occurrence of a localhost address with the given hostname

Types

type Client

type Client func(req *http.Request) (*http.Response, error)

Client sends a request and returns a response or error.

type ErrorCause

type ErrorCause string

ErrorCause is used to identify the type of the ingestError.

const (
	// TrialInactive is returned when the trial had not been started.
	TrialInactive ErrorCause = "trial_inactive"

	// TrialExpired is returned when the trial had expired.
	TrialExpired ErrorCause = "trial_expired"

	// InvalidLicense is returned when the license key is invalid.
	InvalidLicense ErrorCause = "invalid_license"

	// ServiceError is the error returned by the identity service.
	ServiceError ErrorCause = "service_error"
)

func IsResponseUnsuccessful

func IsResponseUnsuccessful(resp *http.Response) (hasError bool, cause ErrorCause)

IsResponseUnsuccessful will return the cause of the error if it's the case.

type Mock

type Mock struct {
	sync.RWMutex

	HttpLibError error
	// contains filtered or unexported fields
}

func NewMockTransport

func NewMockTransport() *Mock

func (*Mock) Append

func (self *Mock) Append(code int, data []byte)

func (*Mock) AppendWithBody

func (self *Mock) AppendWithBody(code int, body interface{})

func (*Mock) RoundTrip

func (self *Mock) RoundTrip(req *http.Request) (*http.Response, error)

func (*Mock) WhenEmpty

func (self *Mock) WhenEmpty(code int, data []byte)

type RequestInterceptorMock added in v1.67.3

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

func NewRequestInterceptorMock added in v1.67.3

func NewRequestInterceptorMock() *RequestInterceptorMock

func (*RequestInterceptorMock) RoundTrip added in v1.67.3

func (r *RequestInterceptorMock) RoundTrip(req *http.Request) (*http.Response, error)

type Response

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

type ResponseMetadata

type ResponseMetadata struct {
	Previous           string                 `json:"previous,omitempty"`
	Next               string                 `json:"next,omitempty"`
	Before             string                 `json:"before,omitempty"`
	After              string                 `json:"after,omitempty"`
	PerPage            int                    `json:"per_page,omitempty"`
	RateLimitLimit     int                    `json:"rate_limit_limit,omitempty"`
	RateLimitRemaining int                    `json:"rate_limit_remaining,omitempty"`
	RateLimitReset     int                    `json:"rate_limit_reset,omitempty"`
	Stats              map[string]interface{} `json:"stats,omitempty"`
}

type ResponseStack

type ResponseStack []*Response

func (ResponseStack) Empty

func (s ResponseStack) Empty() bool

func (ResponseStack) Peek

func (s ResponseStack) Peek() *Response

func (*ResponseStack) Pop

func (s *ResponseStack) Pop() *Response

func (*ResponseStack) Put

func (s *ResponseStack) Put(v *Response)

type RetryPolicy

type RetryPolicy struct {
	After      time.Duration
	MaxBackOff time.Duration
}

RetryPolicy defines the retry behaviour.

type StandardResponse

type StandardResponse struct {
	Payload  interface{}       `json:"payload"`
	Metadata *ResponseMetadata `json:"metadata,omitempty"`
}

Jump to

Keyboard shortcuts

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