go.temporal.io/server/common/headers/headers.go
167 LOC · 73 covered · 94 uncovered · 30 ranges · 3527 concepts · 23 introducers · 1672 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
package headers
import (
"context"
"strings"
commonpb "go.temporal.io/api/common/v1"
"google.golang.org/grpc/metadata"
)
// Note the nexusoperations component references these headers and adds them to a list of disallowed headers for users to set.
// If any other headers are added for internal use, they should be added to the disallowed headers list.
const (
ClientNameHeaderName = "client-name"
ClientVersionHeaderName = "client-version"
SupportedServerVersionsHeaderName = "supported-server-versions"
SupportedFeaturesHeaderName = "supported-features"
SupportedFeaturesHeaderDelim = ","
CallerNameHeaderName = "caller-name"
CallerTypeHeaderName = "caller-type"
CallOriginHeaderName = "call-initiation"
PrincipalTypeHeaderName = "temporal-principal-type"
PrincipalNameHeaderName = "temporal-principal-name"
ExperimentHeaderName = "temporal-experiment"
)
var (
// propagateHeaders are the headers to propagate from the frontend to other services.
propagateHeaders = []string{
ClientNameHeaderName,
ClientVersionHeaderName,
SupportedServerVersionsHeaderName,
SupportedFeaturesHeaderName,
CallerNameHeaderName,
CallerTypeHeaderName,
CallOriginHeaderName,
PrincipalTypeHeaderName,
PrincipalNameHeaderName,
}
)
// GetValues returns header values for passed header names.
// It always returns slice of the same size as number of passed header names.
headerValues := make([]string, len(headerNames))
for i, headerName := range headerNames {
if values := metadata.ValueFromIncomingContext(ctx, headerName); len(values) > 0 {
}
}
}
// Propagate propagates version headers from incoming context to outgoing context.
// It copies all headers to outgoing context only if they are exist in incoming context
// and doesn't exist in outgoing context already.
headersToAppend := make([]string, 0, len(propagateHeaders)*2)
mdOutgoing, mdOutgoingExist := metadata.FromOutgoingContext(ctx)
for _, headerName := range propagateHeaders {
if incomingValue := metadata.ValueFromIncomingContext(ctx, headerName); len(incomingValue) > 0 && len(mdOutgoing.Get(headerName)) == 0 {
}
}
if mdOutgoingExist {
}
}
}
// HeaderGetter is an interface for getting a single header value from a case insensitive key.
type HeaderGetter interface {
Get(string) string
}
// Wrapper for gRPC metadata that exposes a helper to extract a single metadata value.
type GRPCHeaderGetter struct {
ctx context.Context
}
return GRPCHeaderGetter{ctx: ctx}
}
// Get a single value from the underlying gRPC metadata.
// Returns an empty string if the metadata key is unset.
if values := metadata.ValueFromIncomingContext(h.ctx, key); len(values) > 0 {
}
}
// IsExperimentRequested checks if a specific experiment is present in the temporal-experiment header.
// Returns true if the experiment is explicitly listed or if "*" (wildcard) is present.
// Headers exceeding a length of 100 will be skipped.
experimentalValues := metadata.ValueFromIncomingContext(ctx, ExperimentHeaderName)
for _, headerValue := range experimentalValues {
if len(headerValue) > 100 {
}
requested = strings.TrimSpace(requested)
if requested == "*" || requested == experiment {
return true
}
}
}
}
// StripPrincipal removes principal headers from incoming metadata to prevent
// external callers from spoofing principal identity.
mdIncoming, ok := metadata.FromIncomingContext(ctx)
if !ok {
}
mdIncoming.Delete(PrincipalNameHeaderName)
return metadata.NewIncomingContext(ctx, mdIncoming)
}
// SetPrincipal sets the principal type and name headers in the incoming metadata.
func SetPrincipal(ctx context.Context, principal *commonpb.Principal) context.Context {
headers.go ×2
return setIncomingMD(ctx, map[string]string{
PrincipalTypeHeaderName: principal.GetType(),
PrincipalNameHeaderName: principal.GetName(),
})
}
// GetPrincipal retrieves the principal from the context headers. Returns nil if principal is not set.
values := GetValues(ctx, PrincipalTypeHeaderName, PrincipalNameHeaderName)
if values[0] == "" && values[1] == "" {
}
}
// setIncomingMD sets the key-value pairs in the incoming metadata.
// Empty values are ignored.
mdIncoming, ok := metadata.FromIncomingContext(ctx)
if !ok {
}
if v != "" {
mdIncoming.Set(k, v)
}
}
}