Documentation
¶
Overview ¶
Package headerbp provides the shared code for propagating baseplate headers using server and client middlewares.
It is meant to be used by middlewares for different rpc frameworks like http and grpc, not used directly by services.
It is only meant to propagate headers that the server receives, the client middlewares will return an error if they detect a baseplate header in the request being sent.
Index ¶
- Constants
- Variables
- func CheckClientHeader(name string, options ...CheckClientHeaderOption) error
- func HeadersToContext(ctx context.Context, headers map[string]string) context.Context
- func IsBaseplateHeader(key string) bool
- func SetOutgoingHeaders(ctx context.Context, options ...SetOutgoingHeadersOption)
- func SetV2BaseplateHeadersSetter(setter func(context.Context, map[string]string) context.Context)
- type CheckClientHeaderOption
- type CommonHeaderOption
- func WithGRPCClient(service, client, method string) CommonHeaderOption
- func WithGRPCService(service, method string) CommonHeaderOption
- func WithHTTPClient(service, client, endpoint string) CommonHeaderOption
- func WithHTTPService(service, method string) CommonHeaderOption
- func WithThriftClient(service, client, method string) CommonHeaderOption
- func WithThriftService(service, method string) CommonHeaderOption
- type IncomingHeaders
- type NewIncomingHeadersOption
- type SetOutgoingHeadersOption
Constants ¶
const ( IsUntrustedRequestHeaderCanonicalHTTP = "X-Rddt-Untrusted" IsUntrustedRequestHeaderLower = "x-rddt-untrusted" )
Variables ¶
var ErrNewInternalHeaderNotAllowed = fmt.Errorf("cannot send new internal headers on requests")
ErrNewInternalHeaderNotAllowed is returned by a client when the call tries to set an internal header is not allowlisted
Functions ¶
func CheckClientHeader ¶
func CheckClientHeader(name string, options ...CheckClientHeaderOption) error
CheckClientHeader checks if the header is allowlisted and returns an error if it is not.
func HeadersToContext ¶
HeadersToContext can be used to allow interoperability with the v2 library.
func IsBaseplateHeader ¶
IsBaseplateHeader returns true if the header is for baseplate and should be propagated
func SetOutgoingHeaders ¶
func SetOutgoingHeaders(ctx context.Context, options ...SetOutgoingHeadersOption)
SetOutgoingHeaders sets the baseplate headers in the outgoing headers if they have not already been set by the caller.
Types ¶
type CheckClientHeaderOption ¶
type CheckClientHeaderOption interface {
ApplyToCheckClientHeaders(*checkClientHeaders)
}
func WithCheckClientHeaderOptions ¶
func WithCheckClientHeaderOptions(options ...CheckClientHeaderOption) CheckClientHeaderOption
type CommonHeaderOption ¶
type CommonHeaderOption interface {
CheckClientHeaderOption
SetOutgoingHeadersOption
NewIncomingHeadersOption
}
func WithGRPCClient ¶
func WithGRPCClient(service, client, method string) CommonHeaderOption
func WithGRPCService ¶
func WithGRPCService(service, method string) CommonHeaderOption
func WithHTTPClient ¶
func WithHTTPClient(service, client, endpoint string) CommonHeaderOption
func WithHTTPService ¶
func WithHTTPService(service, method string) CommonHeaderOption
func WithThriftClient ¶
func WithThriftClient(service, client, method string) CommonHeaderOption
func WithThriftService ¶
func WithThriftService(service, method string) CommonHeaderOption
type IncomingHeaders ¶
type IncomingHeaders struct {
// contains filtered or unexported fields
}
IncomingHeaders is used to store baseplate headers that are received in a request to a service.
An empty IncomingHeaders is unsafe to use and should be created using NewIncomingHeaders.
func NewIncomingHeaders ¶
func NewIncomingHeaders(options ...NewIncomingHeadersOption) *IncomingHeaders
func (*IncomingHeaders) RecordHeader ¶
func (h *IncomingHeaders) RecordHeader(key, value string)
RecordHeader records the header to be forwarded if it is a baseplate header
func (*IncomingHeaders) SetOnContext ¶
func (h *IncomingHeaders) SetOnContext(ctx context.Context) context.Context
SetOnContext attaches the collected baseplate headers to the context to be forwarded
type NewIncomingHeadersOption ¶
type NewIncomingHeadersOption interface {
ApplyToNewIncomingHeaders(*newIncomingHeaders)
}
func WithNewIncomingHeadersOptions ¶
func WithNewIncomingHeadersOptions(options ...NewIncomingHeadersOption) NewIncomingHeadersOption
type SetOutgoingHeadersOption ¶
type SetOutgoingHeadersOption interface {
ApplyToSetOutgoingHeaders(*setOutgoingHeaders)
}
func WithHeaderSetter ¶
func WithHeaderSetter(setter func(key, value string)) SetOutgoingHeadersOption
func WithSetOutgoingHeadersOptions ¶
func WithSetOutgoingHeadersOptions(options ...SetOutgoingHeadersOption) SetOutgoingHeadersOption