header

package
v0.138.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 0 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package header defines canonical HTTP header name constants used across the fleet. Centralising them here prevents the silent auth bypass that one typo in a string literal can cause.

Import:

import "github.com/baditaflorin/go-common/header"

r.Header.Set(header.APIKey, token)
user := r.Header.Get(header.AuthUser)
Example

Use the constants, not string literals: one typo in an auth header name is a silent bypass.

package main

import (
	"fmt"
	"net/http"

	"github.com/baditaflorin/go-common/header"
)

func main() {
	h := http.Header{}
	h.Set(header.AuthUser, "svc-a")
	fmt.Println(header.AuthUser, h.Get(header.AuthUser))
}
Output:
X-Auth-User svc-a

Index

Examples

Constants

View Source
const (
	// AuthUser is the verified user/service identity injected by the
	// gateway. Presence indicates the gateway already verified the key.
	AuthUser = "X-Auth-User"

	// AuthScope is the verified key scope injected by the gateway.
	// Services that need scope enforcement re-check via apikey.VerifyScope.
	AuthScope = "X-Auth-Scope"

	// AuthTier is the verified key's access tier injected by the gateway
	// (e.g. "open", "free", "vetted-pentest"). Empty/absent means the key
	// predates tiering or was issued with no tier — callers that enforce
	// tiers should treat that as the lowest trust level, never as "all
	// tiers granted".
	AuthTier = "X-Auth-Tier"
)

Inbound auth headers injected by the nginx gateway after a successful /verify call to the keystore. Downstream handlers trust these; they are never set by external clients because the gateway strips them on ingress.

View Source
const (
	// RequestID is generated by middleware.RequestID if absent,
	// then echoed in every response and stamped on every log line.
	RequestID = "X-Request-ID"

	// FleetCaller is optionally set by mesh proxies to identify the
	// calling service when the User-Agent has been rewritten.
	FleetCaller = "X-Fleet-Caller"
)

Request identification headers — threaded through the full request lifecycle for correlation in logs and traces.

View Source
const (
	// ServiceName is the answering service's name, as /health reports it.
	ServiceName = "X-Service-Name"

	// ServiceVersion is the answering service's release, as /version reports it.
	ServiceVersion = "X-Service-Version"
)

Service identity response headers. server.New puts both on every response a service sends (success, error, 404, /health, ...), so a caller can record which release produced an answer even when the body names none. They name the process that wrote the response, never a service whose answer it relays.

View Source
const (
	// AdminToken is the header used to authenticate admin operations
	// against the keystore (/issue, /revoke, /list, /purge).
	AdminToken = "X-Admin-Token"

	// VerifyKey is the header used by the keystore /verify endpoint.
	VerifyKey = "X-Verify-Key"

	// ExpectedScope is set by the nginx gateway on every /verify subrequest
	// to tell the keystore which service hostname is being accessed.
	// The keystore rejects keys whose scope is not "*" and does not include
	// this value. Absent header → no scope enforcement (backward compat).
	ExpectedScope = "X-Expected-Scope"

	// RequiredTier is set by the nginx gateway on a /verify subrequest,
	// from a service's access_tier registry override, to tell the
	// keystore which tier the calling key must have. The keystore
	// rejects a key whose tier doesn't match. Absent header → no tier
	// enforcement (backward compat).
	//
	// This MUST be checked inside the /verify subrequest itself, not via
	// a post-hoc nginx `if` after auth_request returns — nginx's `if`
	// runs in the REWRITE phase, which completes entirely before
	// auth_request's ACCESS-phase subrequest even fires, so any `if`
	// checking an auth_request_set variable always sees it empty,
	// regardless of textual placement in the vhost config. Found live
	// 2026-08-08 (locked every caller out of a real pilot service for a
	// few minutes) — see go_apikey_service's verifyHandler for the fix.
	RequiredTier = "X-Required-Tier"
)

Admin credential headers — used by apikey admin endpoints.

View Source
const (
	// TraceParent is the W3C trace-context propagation header.
	// See https://www.w3.org/TR/trace-context/#traceparent-header
	TraceParent = "Traceparent"

	// TraceState carries vendor-specific trace state alongside TraceParent.
	TraceState = "Tracestate"

	// Baggage carries arbitrary key=value pairs for distributed context.
	Baggage = "Baggage"
)

Tracing headers — W3C Trace Context and custom fleet tracing.

View Source
const (
	ContentType   = "Content-Type"
	Authorization = "Authorization"
	UserAgent     = "User-Agent"
	CacheControl  = "Cache-Control"
	Origin        = "Origin"

	// CORS response headers.
	AccessControlAllowOrigin      = "Access-Control-Allow-Origin"
	AccessControlAllowMethods     = "Access-Control-Allow-Methods"
	AccessControlAllowHeaders     = "Access-Control-Allow-Headers"
	AccessControlExposeHeaders    = "Access-Control-Expose-Headers"
	AccessControlMaxAge           = "Access-Control-Max-Age"
	AccessControlAllowCredentials = "Access-Control-Allow-Credentials"
	AccessControlRequestMethod    = "Access-Control-Request-Method"
	AccessControlRequestHeaders   = "Access-Control-Request-Headers"
)

Standard headers referenced by fleet middleware — kept here so callers don't need to remember the canonical casing.

View Source
const (
	ContentTypeJSON            = "application/json"
	ContentTypeJSONCharsetUTF8 = "application/json; charset=utf-8"
	ContentTypePlainText       = "text/plain"
	ContentTypeFormEncoded     = "application/x-www-form-urlencoded"
	ContentTypeMultipart       = "multipart/form-data"
)

ContentTypes are common MIME type values for Content-Type headers.

View Source
const (
	// APIKey is the fleet API key header sent by service-to-service
	// callers and human-facing clients. Equivalent to Bearer in the
	// Authorization header; both are accepted.
	APIKey = "X-API-Key"
)

Client credential headers — set by callers, read by auth middleware.

Variables

This section is empty.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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