headers

package
v2.260.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 3 Imported by: 20

Documentation

Overview

Package headers package provides header name constants and get/set functions for commonly used http headers in the dp-api-clients-go repo. Package replaces go-ns lib and should be treated as the single source of truth

Index

Constants

View Source
const (
	// IfMatchAnyETag is a wildchar value for If-Match header to ask the API to ignore the ETag check
	IfMatchAnyETag = "*"
)

Variables

View Source
var (
	// ErrHeaderNotFound returned if the requested header is not present in the provided request
	ErrHeaderNotFound = errors.New("header not found")

	// ErrValueEmpty returned if an empty value is passed when a non-empty value is required
	ErrValueEmpty = errors.New("header not set as value was empty")

	// ErrRequestNil return if SetX header function is called with a nil request
	ErrRequestNil = errors.New("error setting request header request was nil")

	// ErrResponseNil return if GetResponseX header function is called with a nil response
	ErrResponseNil = errors.New("error getting request header, response was nil")
)

Functions

func GetAccept added in v2.260.0

func GetAccept(req *http.Request) (string, error)

Get Accept returns the value of the "Accept" request header if it exists, returns ErrHeaderNotFound if the header is not found.

func GetCollectionID

func GetCollectionID(req *http.Request) (string, error)

GetCollectionID returns the value of the "Collection-Id" request header if it exists, returns ErrHeaderNotFound if the header is not found.

func GetDownloadServiceToken

func GetDownloadServiceToken(req *http.Request) (string, error)

GetDownloadServiceToken returns the value of the "X-Download-Service-Token" request header if it exists, returns ErrHeaderNotFound if the header is not found.

func GetETag

func GetETag(req *http.Request) (string, error)

GetETag returns the value of the "ETag" request header if it exists, returns ErrHeaderNotFound if the header is not found.

func GetIfMatch

func GetIfMatch(req *http.Request) (string, error)

GetIfMatch returns the value of the "If-Match" request header if it exists, returns ErrHeaderNotFound if the header is not found.

func GetLocaleCode

func GetLocaleCode(req *http.Request) (string, error)

GetLocaleCode returns the value of the "LocaleCode" request header if it exists, returns ErrHeaderNotFound if the header is not found.

func GetRequestID

func GetRequestID(req *http.Request) (string, error)

GetRequestID returns the value of the "X-Request-Id" request header if it exists, returns ErrHeaderNotFound if the header is not found.

func GetResponseETag

func GetResponseETag(resp *http.Response) (string, error)

GetResponseETag returns the value of "ETag" response header if it exists, returns ErrResponseNil if the header is not found.

func GetServiceAuthToken

func GetServiceAuthToken(req *http.Request) (string, error)

GetServiceAuthToken returns the value of the "Authorization" request header if it exists, returns ErrHeaderNotFound if the header is not found. If the header exists the "Bearer " prefixed is removed from returned value.

func GetUserAuthToken

func GetUserAuthToken(req *http.Request) (string, error)

GetUserAuthToken returns the value of the "X-Florence-Token" request header if it exists, returns ErrHeaderNotFound if the header is not found.

func GetUserIdentity

func GetUserIdentity(req *http.Request) (string, error)

GetUserIdentity returns the value of the "User-Identity" request header if it exists, returns ErrHeaderNotFound if the header is not found.

func IsErrNotFound

func IsErrNotFound(err error) bool

IsErrNotFound return true if the err equal to ErrHeaderNotFound. Return false otherwise

func IsNotErrNotFound

func IsNotErrNotFound(err error) bool

IsNotErrNotFound return true if error is not nil and not equal to ErrHeaderNotFound

func SetAccept added in v2.260.0

func SetAccept(req *http.Request, headerValue string) error

SetAccept set the Accept header on the provided request. If this header is already present it will be overwritten by the new value. If the header value is empty returns ErrValueEmpty

func SetAcceptedLang added in v2.7.1

func SetAcceptedLang(req *http.Request, headerValue string) error

func SetAuthToken

func SetAuthToken(req *http.Request, headerValue string) error

SetAuthToken set the access token header on the provided request. If the access token is already present it will be overwritten by the new value. Empty values are allowed for this header.

func SetCollectionID

func SetCollectionID(req *http.Request, headerValue string) error

SetCollectionID set the collection ID header on the provided request. If the collection ID header is already present in the request it will be overwritten by the new value. Empty values are allowed for this header

func SetDownloadServiceToken

func SetDownloadServiceToken(req *http.Request, headerValue string) error

SetDownloadServiceToken set the download service auth token header on the provided request. If the authentication token is already present it will be overwritten by the new value. Empty values are allowed for this header.

func SetETag

func SetETag(req *http.Request, headerValue string) error

SetETag set the ETag header on the provided request. If this header is already present it will be overwritten by the new value. Empty values are allowed for this header.

func SetIDTokenHeader added in v2.1.11

func SetIDTokenHeader(req *http.Request, headerValue string) error

SetIDTokenHeader set the ID token header on the provided request. If the authentication token is already present it will be overwritten by the new value. Empty values are allowed for this header.

func SetIfMatch

func SetIfMatch(req *http.Request, headerValue string) error

SetIfMatch set the If-Match header on the provided request. If this header is already present it will be overwritten by the new value. Empty values are allowed for this header.

func SetLocaleCode

func SetLocaleCode(req *http.Request, headerValue string) error

SetLocaleCode set the locale code header on the provided request. If this header is already present it will be overwritten by the new value. Empty values are allowed for this header.

func SetRefreshTokenHeader added in v2.1.11

func SetRefreshTokenHeader(req *http.Request, headerValue string) error

SetRefreshTokenHeader set the refresh token header on the provided request. If the authentication token is already present it will be overwritten by the new value. Empty values are allowed for this header.

func SetRequestID

func SetRequestID(req *http.Request, headerValue string) error

SetRequestID set the unique request ID header on the provided request. If a request ID header is already present it will be overwritten by the new value. Empty values are allowed for this header.

func SetServiceAuthToken

func SetServiceAuthToken(req *http.Request, headerValue string) error

SetServiceAuthToken set the service authentication token header on the provided request. If the authentication token is already present it will be overwritten by the new value. Empty values are allowed for this header. Replaces deprecated SetUserAuthToken function.

func SetUserIdentity

func SetUserIdentity(req *http.Request, headerValue string) error

SetUserIdentity set the user identity header on the provided request. If a user identity token is already present it will be overwritten by the new value. Empty values are allowed for this header.

Types

This section is empty.

Jump to

Keyboard shortcuts

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