utils

package
v0.0.0-...-84400b0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2022 License: MIT-0 Imports: 17 Imported by: 0

Documentation

Overview

Package utils defines utilities for the agent.

Index

Constants

View Source
const (
	// PendingPath is the URL subpath for pending requests held by the proxy.
	PendingPath = "agent/pending"

	// RequestPath is the URL subpath for reading a specific request held by the proxy.
	RequestPath = "agent/request"

	// ResponsePath is the URL subpath for posting a request response to the proxy.
	ResponsePath = "agent/response"

	// HeaderUserID is the name of a response header used by the proxy to identify the end user.
	HeaderUserID = "X-Inverting-Proxy-User-ID"

	// HeaderBackendID is the name of a request header used to uniquely identify this agent.
	HeaderBackendID = "X-Inverting-Proxy-Backend-ID"

	// HeaderVMID is the name of a request header used to report the VM
	// (if any) on which the agent is running.
	HeaderVMID = "X-Inverting-Proxy-VM-ID"

	// HeaderRequestID is the name of a request/response header used to uniquely
	// identify a proxied request.
	HeaderRequestID = "X-Inverting-Proxy-Request-ID"

	// HeaderRequestStartTime is the name of a response header used by the proxy
	// to report the start time of a proxied request.
	HeaderRequestStartTime = "X-Inverting-Proxy-Request-Start-Time"

	// JitterPercent sets the jitter for exponential backoff retry time
	JitterPercent = 0.1
)

Variables

This section is empty.

Functions

func ExponentialBackoffDuration

func ExponentialBackoffDuration(retryCount uint) time.Duration

ExponentialBackoffDuration gets time to wait before retry for exponential backoff

func ListPendingRequests

func ListPendingRequests(client *http.Client, proxyHost, backendID string, metricHandler *metrics.MetricHandler) ([]string, error)

ListPendingRequests issues a single request to the proxy to ask for the IDs of pending requests.

func ReadRequest

func ReadRequest(client *http.Client, proxyHost, backendID, requestID string, callback RequestCallback, metricHandler *metrics.MetricHandler) error

ReadRequest reads a forwarded client request from the inverting proxy.

If the returned request is non-nil, then it is passed to the provided callback.

func RoundTripperWithVMIdentityAWS

func RoundTripperWithVMIdentityAWS(ctx context.Context, wrapped http.RoundTripper, proxyURL string, disableEC2 bool, AWSConfig aws.Config) http.RoundTripper

Types

type ForwardedRequest

type ForwardedRequest struct {
	BackendID string
	RequestID string
	User      string
	StartTime time.Time

	Contents *http.Request
}

ForwardedRequest represents an end-client HTTP request that was forwarded to us by the inverting proxy.

type PendingRequests

type PendingRequests []string

PendingRequests represents a list of request IDs that do not yet have a response.

type RequestCallback

type RequestCallback func(client *http.Client, fr *ForwardedRequest) error

RequestCallback defines how the caller of `ReadRequest` uses the request that was read.

This is done as a callback so that the caller of `ReadRequest` does not have to remember to call `Close()` on the nested *http.Request object's body.

type ResponseForwarder

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

ResponseForwarder implements http.ResponseWriter by dumping a wire-compatible representation of the response to 'proxyWriter' field.

ResponseForwarder is used by the agent to forward a response from the backend target to the inverting proxy.

func NewResponseForwarder

func NewResponseForwarder(client *http.Client, proxyHost, backendID, requestID string) (*ResponseForwarder, error)

NewResponseForwarder constructs a new ResponseForwarder that forwards to the given proxy for the specified request.

func (*ResponseForwarder) Close

func (rf *ResponseForwarder) Close() error

Close signals that the response has been fully read from the backend server, waits for that response to be forwarded to the proxy, and then reports any errors that occured while forwarding the response.

func (*ResponseForwarder) Header

func (rf *ResponseForwarder) Header() http.Header

Header implements the http.ResponseWriter interface.

func (*ResponseForwarder) Write

func (rf *ResponseForwarder) Write(buf []byte) (int, error)

Write implements the http.ResponseWriter interface.

func (*ResponseForwarder) WriteHeader

func (rf *ResponseForwarder) WriteHeader(code int)

WriteHeader implements the http.ResponseWriter interface.

Jump to

Keyboard shortcuts

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