echo

package
v0.0.0-...-518b544 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: Apache-2.0 Imports: 17 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	URLFieldRegex          = regexp.MustCompile(string(URLField) + "=(.*)")
	ClusterFieldRegex      = regexp.MustCompile(string(ClusterField) + "=(.*)")
	IstioVersionFieldRegex = regexp.MustCompile(string(IstioVersionField) + "=(.*)")
	IPFieldRegex           = regexp.MustCompile(string(IPField) + "=(.*)")
	SourceIPFieldRegex     = regexp.MustCompile(string(SourceIPField) + "=(.*)")
)
View Source
var GlobalEchoRequests = atomic.NewUint64(0)

GlobalEchoRequests records how many echo calls we have made total, from all sources. Note: go tests are distinct binaries per test suite, so this is the suite level number of calls

Functions

func WriteBodyLine

func WriteBodyLine(out io.StringWriter, requestID int, line string)

func WriteError

func WriteError(out io.StringWriter, requestID int, err error)

Types

type Client

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

Client of an Echo server that simplifies request/response processing for Forward commands.

func New

func New(address string, tlsSettings *common.TLSSettings, extraDialOpts ...grpc.DialOption) (*Client, error)

New creates a new echo client.Instance that is connected to the given server address.

func (*Client) Close

func (c *Client) Close() error

Close the EchoClient and free any resources.

func (*Client) Echo

func (c *Client) Echo(ctx context.Context, request *proto.EchoRequest) (Response, error)

func (*Client) ForwardEcho

func (c *Client) ForwardEcho(ctx context.Context, request *proto.ForwardEchoRequest) (Responses, error)

ForwardEcho sends the given forward request and parses the response for easier processing. Only fails if the request fails.

type Field

type Field string

Field is a list of fields returned in responses from the Echo server.

const (
	RequestIDField        Field = "X-Request-Id"
	ServiceVersionField   Field = "ServiceVersion"
	ServicePortField      Field = "ServicePort"
	StatusCodeField       Field = "StatusCode"
	URLField              Field = "URL"
	ForwarderURLField     Field = "Url"
	ForwarderMessageField Field = "Echo"
	ForwarderHeaderField  Field = "Header"
	HostField             Field = "Host"
	HostnameField         Field = "Hostname"
	NamespaceField        Field = "Namespace"
	MethodField           Field = "Method"
	ProtocolField         Field = "Proto"
	ProxyProtocolField    Field = "ProxyProtocol"
	AlpnField             Field = "Alpn"
	RequestHeaderField    Field = "RequestHeader"
	ResponseHeaderField   Field = "ResponseHeader"
	ClusterField          Field = "Cluster"
	IstioVersionField     Field = "IstioVersion"
	IPField               Field = "IP"       // The Requester’s IP Address, as reported from the destination
	SourceIPField         Field = "SourceIP" // The Requester’s IP Address, as reported from the source.
	LatencyField          Field = "Latency"
	ActiveRequestsField   Field = "ActiveRequests"
	DNSProtocolField      Field = "Protocol"
	DNSQueryField         Field = "Query"
	DNSServerField        Field = "DnsServer"
	CipherField           Field = "Cipher"
	TLSVersionField       Field = "Version"
	TLSServerName         Field = "ServerName"
)

func (Field) String

func (f Field) String() string

func (Field) Write

func (f Field) Write(out io.StringWriter, value string)

func (Field) WriteForRequest

func (f Field) WriteForRequest(out io.StringWriter, requestID int, value string)

func (Field) WriteKeyValue

func (f Field) WriteKeyValue(out io.StringWriter, key, value string)

func (Field) WriteKeyValueForRequest

func (f Field) WriteKeyValueForRequest(out io.StringWriter, requestID int, key, value string)

func (Field) WriteNonEmpty

func (f Field) WriteNonEmpty(out io.StringWriter, value string)

type HeaderType

type HeaderType string

HeaderType is a helper enum for retrieving Headers from a Response.

const (
	RequestHeader  HeaderType = "request"
	ResponseHeader HeaderType = "response"
)

type Response

type Response struct {
	// RequestURL is the requested URL. This differs from URL, which is the just the path.
	// For example, RequestURL=http://foo/bar, URL=/bar
	RequestURL string
	// Method used (for HTTP).
	Method string
	// Protocol used for the request.
	Protocol string
	// Alpn value (for HTTP).
	Alpn string
	// ProxyProtocol value.
	ProxyProtocol string
	// RawContent is the original unparsed content for this response
	RawContent string
	// ID is a unique identifier of the resource in the response
	ID string
	// URL is the url the request is sent to
	URL string
	// Version is the version of the resource in the response
	Version string
	// Port is the port of the resource in the response
	Port string
	// Code is the response code
	Code string
	// Host is the host called by the request
	Host string
	// Hostname is the host that responded to the request
	Hostname string
	// The cluster where the server is deployed.
	Cluster string
	// IstioVersion for the Istio sidecar.
	IstioVersion string
	// IP is the client IP, as seen by the server.
	IP string
	// SourceIP is the client's source IP. This can differ from IP when there are multiple hops.
	SourceIP string
	// RawBody gives a map of all key/values in the body of the response.
	RawBody         map[string]string
	RequestHeaders  http.Header
	ResponseHeaders http.Header
}

Response represents a response to a single echo request.

func (Response) Body

func (r Response) Body() []string

Body returns the lines of the response body, in order

func (Response) Count

func (r Response) Count(text string) int

Count occurrences of the given text within the body of this response.

func (Response) GetHeaders

func (r Response) GetHeaders(hType HeaderType) http.Header

GetHeaders returns the appropriate headers for the given type.

func (Response) String

func (r Response) String() string

type Responses

type Responses []Response

Responses is an ordered list of parsed response objects.

func (Responses) Count

func (r Responses) Count(text string) int

Count occurrences of the given text within the bodies of all responses.

func (Responses) IsEmpty

func (r Responses) IsEmpty() bool

func (Responses) Len

func (r Responses) Len() int

Len returns the length of the parsed responses.

func (Responses) Match

func (r Responses) Match(f func(r Response) bool) Responses

Match returns a subset of Responses that match the given predicate.

func (Responses) String

func (r Responses) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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