headers

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2021 License: Apache-2.0 Imports: 7 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 (

	// ValueApplicationJSON represents the HTTP Header Value of "application/json"
	ValueApplicationJSON = "application/json"
	// 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="

	// 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"
)

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

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 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 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 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 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 identier 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

Jump to

Keyboard shortcuts

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