Documentation ¶
Overview ¶
Package utils defines utilities for the agent.
Index ¶
- Constants
- func ExponentialBackoffDuration(retryCount uint) time.Duration
- func ListPendingRequests(client *http.Client, proxyHost, backendID string, ...) ([]string, error)
- func ReadRequest(client *http.Client, proxyHost, backendID, requestID string, ...) error
- func RoundTripperWithVMIdentity(ctx context.Context, wrapped http.RoundTripper, proxyURL string, ...) http.RoundTripper
- func ShutdownSignalChan() <-chan struct{}
- type ForwardedRequest
- type PendingRequests
- type RequestCallback
- type ResponseWriteCloser
- type StreamingResponseWriter
Constants ¶
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 ¶
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 RoundTripperWithVMIdentity ¶
func RoundTripperWithVMIdentity(ctx context.Context, wrapped http.RoundTripper, proxyURL string, disableGCEVM bool) http.RoundTripper
RoundTripperWithVMIdentity returns an http.RoundTripper that includes a GCE VM ID token in every outbound request. The token is fetched from the metadata server and stored in the 'X-Inverting-Proxy-VM-ID' header.
This method relies on the Google Compute Engine functionality for verifying a VM's identity (https://cloud.google.com/compute/docs/instances/verifying-instance-identity), so it if this is not running inside of a Google Compute Engine VM, then it just returns the passed in RoundTripper.
func ShutdownSignalChan ¶
func ShutdownSignalChan() <-chan struct{}
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 ResponseWriteCloser ¶
type ResponseWriteCloser interface { http.ResponseWriter io.Closer }
ResponseWriteCloser combines the http.ResponseWriter and io.Closer interfaces.
func NewResponseForwarder ¶
func NewResponseForwarder(client *http.Client, proxyHost, backendID, requestID string, r *http.Request, metricHandler *metrics.MetricHandler) (ResponseWriteCloser, error)
NewResponseForwarder constructs a new ResponseWriteCloser that forwards to the given proxy for the specified request.
type StreamingResponseWriter ¶
type StreamingResponseWriter interface { ResponseWriteCloser // CloseWithError signals to any clients of the ResponseWriter that further // writes to the response are not being processed, and specifies the error that // should be returned to those writers to indicate this. // // This should only be called by the code that is processing the written response. CloseWithError(error) error }
StreamingResponseWriter is a ResponseWriteCloser with an additional method to notify writers that the streamed response is no longer being consumed due to an error.
func NewStreamingResponseWriter ¶
func NewStreamingResponseWriter(respChan chan *http.Response, r *http.Request) StreamingResponseWriter
NewStreamingResponseWriter returns a ResponseWriteCloser that forwards the written response to the given channel.
The response is sent to the given channel as soon as the status code is set, the response body is streamed as soon as each successive call to the ResponseWriter's `Write` method is invoked, and the trailers are made available once the `Close` method is called.
The caller that passes this ResponseWriter to an http.Handler is responsible for closing the writer as soon as the call to the handler's `ServeHTTP` method completes.
If the caller hits an error before reading all of the streamed returned response's body, then it should call `CloseWithError` to propogate this error to any remaining writers of the response body.
Any hop-by-hop headers are filtered out from both the response header and trailer.