Help us shape the future of Go! Take the 2026 Go Developer Survey

headers

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

headers/headers.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckDeprecationHeader

func CheckDeprecationHeader(resp *http.Response, log logger.Logger)

CheckDeprecationHeader checks the response headers for the Deprecation header and logs a warning if present.

func HeadersToString

func HeadersToString(headers http.Header) string

HeadersToString converts a http.Header to a string for logging, with each header on a new line for readability.

func SetAcceptEncodingHeader

func SetAcceptEncodingHeader(req *http.Request, acceptEncodingValue string)

SetAcceptEncodingHeader sets the Accept-Encoding header for an HTTP request. This header indicates the type of encoding (e.g., gzip) the client can handle.

func SetCacheControlHeader

func SetCacheControlHeader(req *http.Request, cacheControlValue string)

SetCacheControlHeader sets the Cache-Control header for an HTTP request. This header specifies directives for caching mechanisms in requests and responses.

func SetConditionalHeaders

func SetConditionalHeaders(req *http.Request, ifModifiedSince, ifNoneMatch string)

SetConditionalHeaders sets the If-Modified-Since and If-None-Match headers for an HTTP request. These headers make a request conditional to ask the server to return content only if it has changed.

func SetCustomHeader

func SetCustomHeader(req *http.Request, headerName, headerValue string)

SetCustomHeader sets a custom header for an HTTP request. This function allows setting arbitrary headers for specialized API requirements.

func SetRefererHeader

func SetRefererHeader(req *http.Request, refererValue string)

SetRefererHeader sets the Referer header for an HTTP request. This header indicates the address of the previous web page from which a link was followed.

func SetXForwardedForHeader

func SetXForwardedForHeader(req *http.Request, xForwardedForValue string)

SetXForwardedForHeader sets the X-Forwarded-For header for an HTTP request. This header is used to identify the originating IP address of a client connecting through a proxy.

Types

type HeaderHandler

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

HeaderHandler is responsible for managing and setting headers on HTTP requests.

func NewHeaderHandler

func NewHeaderHandler(req *http.Request, log logger.Logger, apiHandler apihandler.APIHandler, authTokenHandler *authenticationhandler.AuthTokenHandler) *HeaderHandler

NewHeaderHandler creates a new instance of HeaderHandler for a given http.Request, logger, and APIHandler.

func (*HeaderHandler) LogHeaders

func (h *HeaderHandler) LogHeaders(hideSensitiveData bool)

LogHeaders prints all the current headers in the http.Request using the zap logger. It uses the RedactSensitiveHeaderData function to redact sensitive data based on the hideSensitiveData flag.

func (*HeaderHandler) SetAccept

func (h *HeaderHandler) SetAccept(acceptHeader string)

SetAccept sets the Accept header for the request.

func (*HeaderHandler) SetAuthorization

func (h *HeaderHandler) SetAuthorization()

SetAuthorization sets the Authorization header for the request.

func (*HeaderHandler) SetContentType

func (h *HeaderHandler) SetContentType(contentType string)

SetContentType sets the Content-Type header for the request.

func (*HeaderHandler) SetRequestHeaders

func (h *HeaderHandler) SetRequestHeaders(endpoint string)

SetRequestHeaders sets the necessary HTTP headers for a given request using the APIHandler to determine the required headers.

func (*HeaderHandler) SetUserAgent

func (h *HeaderHandler) SetUserAgent(userAgent string)

SetUserAgent sets the User-Agent header for the request.

Directories

Path Synopsis
headers/redact/redact.go
headers/redact/redact.go

Jump to

Keyboard shortcuts

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