Documentation ¶
Overview ¶
headers/headers.go
Index ¶
- func CheckDeprecationHeader(resp *http.Response, log logger.Logger)
- func HeadersToString(headers http.Header) string
- func SetAcceptEncodingHeader(req *http.Request, acceptEncodingValue string)
- func SetCacheControlHeader(req *http.Request, cacheControlValue string)
- func SetConditionalHeaders(req *http.Request, ifModifiedSince, ifNoneMatch string)
- func SetCustomHeader(req *http.Request, headerName, headerValue string)
- func SetRefererHeader(req *http.Request, refererValue string)
- func SetUserAgentHeader() string
- func SetXForwardedForHeader(req *http.Request, xForwardedForValue string)
- type HeaderHandler
- func (h *HeaderHandler) LogHeaders(hideSensitiveData bool)
- func (h *HeaderHandler) SetAccept(acceptHeader string)
- func (h *HeaderHandler) SetAuthorization()
- func (h *HeaderHandler) SetContentType(contentType string)
- func (h *HeaderHandler) SetRequestHeaders(endpoint string)
- func (h *HeaderHandler) SetUserAgent(userAgent string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckDeprecationHeader ¶
CheckDeprecationHeader checks the response headers for the Deprecation header and logs a warning if present.
func HeadersToString ¶
HeadersToString converts a http.Header to a string for logging, with each header on a new line for readability.
func SetAcceptEncodingHeader ¶
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 ¶
SetCacheControlHeader sets the Cache-Control header for an HTTP request. This header specifies directives for caching mechanisms in requests and responses.
func SetConditionalHeaders ¶
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 ¶
SetCustomHeader sets a custom header for an HTTP request. This function allows setting arbitrary headers for specialized API requirements.
func SetRefererHeader ¶
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 SetUserAgentHeader ¶ added in v0.1.21
func SetUserAgentHeader() string
SetUserAgentHeader sets the User-Agent header for an HTTP request.
func SetXForwardedForHeader ¶
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.