headerbp

package
v0.10.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: BSD-3-Clause Imports: 7 Imported by: 0

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

View Source
const (
	IsUntrustedRequestHeaderCanonicalHTTP = "X-Rddt-Untrusted"
	IsUntrustedRequestHeaderLower         = "x-rddt-untrusted"
)

Variables

View Source
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

func HeadersToContext(ctx context.Context, headers map[string]string) context.Context

HeadersToContext can be used to allow interoperability with the v2 library.

func IsBaseplateHeader

func IsBaseplateHeader(key string) bool

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.

func SetV2BaseplateHeadersSetter

func SetV2BaseplateHeadersSetter(setter func(context.Context, map[string]string) context.Context)

SetV2BaseplateHeadersSetter sets the function to use to set baseplate headers in the v2 library.

Types

type CheckClientHeaderOption

type CheckClientHeaderOption interface {
	ApplyToCheckClientHeaders(*checkClientHeaders)
}

func WithCheckClientHeaderOptions

func WithCheckClientHeaderOptions(options ...CheckClientHeaderOption) CheckClientHeaderOption

type CommonHeaderOption

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

Jump to

Keyboard shortcuts

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