headers

package
v2.0.0-beta2.0...-3469a79 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package headers provides functionality for HTTP Headers not provided by the builtin net/http package

Index

Constants

View Source
const (
	// NameVia represents the HTTP Header Name of "Via"
	NameVia = "Via"
	// NameForwarded reqresents the HTTP Header Name of "Forwarded"
	NameForwarded = "Forwarded"
	// NameXForwardedFor represents the HTTP Header Name of "X-Forwarded-For"
	NameXForwardedFor = "X-Forwarded-For"
	// NameXForwardedServer represents the HTTP Header Name of "X-Forwarded-Server"
	NameXForwardedServer = "X-Forwarded-Server"
	// NameXForwardedHost represents the HTTP Header Name of "X-Forwarded-Host"
	NameXForwardedHost = "X-Forwarded-Host"
	// NameXForwardedProto represents the HTTP Header Name of "X-Forwarded-Proto"
	NameXForwardedProto = "X-Forwarded-Proto"
)
View Source
const (

	// ValueApplicationCSV represents the HTTP Header Value of "application/csv"
	ValueApplicationCSV = "application/csv"
	// ValueApplicationJSON represents the HTTP Header Value of "application/json"
	ValueApplicationJSON = "application/json"
	// ValueApplicationFlux represents the HTTP Header Value of "application/vnd.flux"
	ValueApplicationFlux = "application/vnd.flux"
	// ValueChunked represents the HTTP Header Value of "chunked"
	ValueChunked = "chunked"
	// ValueClose represents the HTTP Header Value of "close"
	ValueClose = "close"
	// ValueMaxAge represents the HTTP Header Value of "max-age"
	ValueMaxAge = "max-age"
	// ValueMultipartFormData represents the HTTP Header Value of "multipart/form-data"
	ValueMultipartFormData = "multipart/form-data"
	// ValueMustRevalidate represents the HTTP Header Value of "must-revalidate"
	ValueMustRevalidate = "must-revalidate"
	// ValueNoCache represents the HTTP Header Value of "no-cache"
	ValueNoCache = "no-cache"
	// ValueNoStore represents the HTTP Header Value of "no-store"
	ValueNoStore = "no-store"
	// ValueNoTransform represents the HTTP Header Value of "no-transform"
	ValueNoTransform = "no-transform"
	// ValuePrivate represents the HTTP Header Value of "private"
	ValuePrivate = "private"
	// ValueProxyRevalidate represents the HTTP Header Value of "proxy-revalidate"
	ValueProxyRevalidate = "proxy-revalidate"
	// ValuePublic represents the HTTP Header Value of "public"
	ValuePublic = "public"
	// ValueSharedMaxAge represents the HTTP Header Value of "s-maxage"
	ValueSharedMaxAge = "s-maxage"
	// ValueTextPlain represents the HTTP Header Value of "text/plain"
	ValueTextPlain = "text/plain"
	// ValueXFormURLEncoded represents the HTTP Header Value of "application/x-www-form-urlencoded"
	ValueXFormURLEncoded = "application/x-www-form-urlencoded"

	// ValueMultipartByteRanges represents the HTTP Header prefix for a Multipart Byte Range response
	ValueMultipartByteRanges = "multipart/byteranges; boundary="

	// NameAccept represents the HTTP Header Name of "Accept"
	NameAccept = "Accept"
	// NameCacheControl represents the HTTP Header Name of "Cache-Control"
	NameCacheControl = "Cache-Control"
	// NameAllowOrigin represents the HTTP Header Name of "Access-Control-Allow-Origin"
	NameAllowOrigin = "Access-Control-Allow-Origin"
	// NameConnection represents the HTTP Header Name of "Connection"
	NameConnection = "Connection"
	// NameContentType represents the HTTP Header Name of "Content-Type"
	NameContentType = "Content-Type"
	// NameContentEncoding represents the HTTP Header Name of "Content-Encoding"
	NameContentEncoding = "Content-Encoding"
	// NameContentLength represents the HTTP Header Name of "Content-Length"
	NameContentLength = "Content-Length"
	// NameAuthorization represents the HTTP Header Name of "Authorization"
	NameAuthorization = "Authorization"
	// NameContentRange represents the HTTP Header Name of "Content-Range"
	NameContentRange = "Content-Range"
	// NameTricksterResult represents the HTTP Header Name of "X-Trickster-Result"
	NameTricksterResult = "X-Trickster-Result"
	// NameAcceptEncoding represents the HTTP Header Name of "Accept-Encoding"
	NameAcceptEncoding = "Accept-Encoding"
	// NameSetCookie represents the HTTP Header Name of "Set-Cookie"
	NameSetCookie = "Set-Cookie"
	// NameRange represents the HTTP Header Name of "Range"
	NameRange = "Range"
	// NameTransferEncoding represents the HTTP Header Name of "Transfer-Encoding"
	NameTransferEncoding = "Transfer-Encoding"
	// NameIfModifiedSince represents the HTTP Header Name of "If-Modified-Since"
	NameIfModifiedSince = "If-Modified-Since"
	// NameIfUnmodifiedSince represents the HTTP Header Name of "If-Unodified-Since"
	NameIfUnmodifiedSince = "If-Unmodified-Since"
	// NameIfNoneMatch represents the HTTP Header Name of "If-None-Match"
	NameIfNoneMatch = "If-None-Match"
	// NameIfMatch represents the HTTP Header Name of "If-Match"
	NameIfMatch = "If-Match"
	// NameDate represents the HTTP Header Name of "date"
	NameDate = "Date"
	// NamePragma represents the HTTP Header Name of "pragma"
	NamePragma = "Pragma"
	// NameProxyAuthenticate represents the HTTP Header Name of "Proxy-Authenticate"
	NameProxyAuthenticate = "Proxy-Authenticate"
	// NameProxyAuthorization represents the HTTP Header Name of "Proxy-Authorization"
	NameProxyAuthorization = "Proxy-Authorization"
	// NameProxyConnection represents the HTTP Header Name of "Proxy-Connection"
	NameProxyConnection = "Proxy-Connection"
	// NameKeepAlive represents the HTTP Header Name of "Keep-Alive"
	NameKeepAlive = "Keep-Alive"
	// NameLastModified represents the HTTP Header Name of "last-modified"
	NameLastModified = "Last-Modified"
	// NameExpires represents the HTTP Header Name of "expires"
	NameExpires = "Expires"
	// NameETag represents the HTTP Header Name of "etag"
	NameETag = "Etag"
	// NameLocation represents the HTTP Header Name of "location"
	NameLocation = "Location"
	// NameTe represents the HTTP Header Name of "TE"
	NameTe = "Te"
	// NameTrailer represents the HTTP Header Name of "Trailer"
	NameTrailer = "Trailer"
	// NameUpgrade represents the HTTP Header Name of "Upgrade"
	NameUpgrade = "Upgrade"

	// NameTrkHCStatus represents the HTTP Header Name of "Trk-HC-Status"
	NameTrkHCStatus = "Trk-HC-Status"
	// NameTrkHCDetail represents the HTTP Header Name of "Trk-HC-Detail"
	NameTrkHCDetail = "Trk-HC-Detail"
)

Variables

ForwardingHeaders defines a list of headers that Proxies use to identify themselves in a request

HopHeaders defines a list of headers that Proxies should not pass through

MergeRemoveHeaders defines a list of headers that should be removed when Merging time series results

Functions

func AddForwarded

func AddForwarded(r *http.Request, hop *Hop)

AddForwarded sets or appends to the standard Forwarded header to the provided request

func AddForwardedAndX

func AddForwardedAndX(r *http.Request, hop *Hop)

AddForwardedAndX sets or appends to the to the "X-Forwarded-*" headers headers, and to the standard Forwarded header to the provided request

func AddForwardingHeaders

func AddForwardingHeaders(r *http.Request, headerType string)

AddForwardingHeaders sets or appends to the forwarding headers to the provided request

func AddResponseHeaders

func AddResponseHeaders(h http.Header)

AddResponseHeaders injects standard Trickster headers into downstream HTTP responses

func AddXForwarded

func AddXForwarded(r *http.Request, hop *Hop)

AddXForwarded sets or appends to the "X-Forwarded-*" headers to the provided request

func ExtractHeader

func ExtractHeader(headers http.Header, header string) (string, bool)

ExtractHeader returns the value for the provided header name, and a boolean indicating if the header was present

func HideAuthorizationCredentials

func HideAuthorizationCredentials(headers Lookup)

HideAuthorizationCredentials replaces any sensitive HTTP header values with 5 asterisks sensitive headers are defined in the sensitiveCredentials map

func IsValidForwardingType

func IsValidForwardingType(input string) bool

IsValidForwardingType returns true if the input is a valid Forwarding Type name Valid names comprise the keys of the forwardingFuncs map

func LogString

func LogString(h http.Header) string

LogString returns a compact string representation of the headers suitable for use with logging

func MakeResultsHeader

func MakeResultsHeader(engine, status, ffstatus string, fetched timeseries.ExtentList) string

MakeResultsHeader returns a header value summarizing Trickster's handling of the HTTP request

func Merge

func Merge(dst, src http.Header)

Merge merges the source http.Header map into destination map. If a key exists in both maps, the source value wins. If the destination map is nil, the source map will not be merged

func MergeResultHeaderVals

func MergeResultHeaderVals(h1, h2 string) string

MergeResultHeaderVals merges 2 Trickster Result Headers

func SetResultsHeader

func SetResultsHeader(headers http.Header, engine, status, ffstatus string, fetched timeseries.ExtentList)

SetResultsHeader adds a response header summarizing Trickster's handling of the HTTP request

func SetVia

func SetVia(r *http.Request, hop *Hop)

SetVia sets the "Via" header to the provided request

func String

func String(h http.Header) string

String returns the string representation of the headers as if they were transmitted over the wire (Header1: value1\nHeader2: value2\n\n)

func StripClientHeaders

func StripClientHeaders(h http.Header)

StripClientHeaders strips certain headers from the HTTP request to facililate acceleration

func StripForwardingHeaders

func StripForwardingHeaders(h http.Header)

StripForwardingHeaders strips certain headers from the HTTP request to facililate acceleration

func StripMergeHeaders

func StripMergeHeaders(h http.Header)

StripMergeHeaders strips certain headers from the HTTP request to facililate acceleration when merging HTTP responses from multiple origins

func UpdateHeaders

func UpdateHeaders(headers http.Header, updates map[string]string)

UpdateHeaders updates the provided headers collection with the provided updates

Types

type Hop

type Hop struct {
	// RemoteAddr is the client address for which the request is being forwarded.
	RemoteAddr string
	// Host header as received by the proxy
	Host string
	// Scheme is the protocol scheme requested of the proxy
	Scheme string
	// Server is an identifier for the server running the Trickster process
	Server string
	// protocol indicates the HTTP protocol Version in proper format (.eg., "HTTP/1.1")
	// requested by the client
	Protocol string
	// Hops is a list of previous X-Forwarded-For or Forwarded headers to which we can append our hop
	Hops Hops
	// Via is the previous Via header, we will append ours to it.
	Via string
}

Hop describes a collection of data about the forwarded request to be used in Via, Forwarded and X-Forwarded-* headers

func HopsFromRequest

func HopsFromRequest(r *http.Request) *Hop

HopsFromRequest extracts a Hop reference that includes a list of any previous hops

func (*Hop) String

func (hop *Hop) String(expand ...bool) string

String returns a "Forwarded" Header value

func (*Hop) XHeader

func (hop *Hop) XHeader() http.Header

XHeader returns an http.Header containing the "X-Forwarded-*" headers

type Hops

type Hops []*Hop

Hops defines a list of Hop References

func HopsFromHeader

func HopsFromHeader(h http.Header) Hops

HopsFromHeader extracts a hop from the header

type Lookup

type Lookup map[string]string

Lookup represents a simple lookup for internal header manipulation

func (Lookup) Clone

func (l Lookup) Clone() Lookup

Clone returns an exact copy of the subject Lookup

func (Lookup) ToHeader

func (l Lookup) ToHeader() http.Header

ToHeader returns an http.Header version of a simple header Lookup

type ResultHeaderParts

type ResultHeaderParts struct {
	Engine            string
	Status            string
	Fetched           timeseries.ExtentList
	FastForwardStatus string
}

ResultHeaderParts defines the components for building the Trickster Result Header

func (ResultHeaderParts) String

func (p ResultHeaderParts) String() string

Jump to

Keyboard shortcuts

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