Documentation
¶
Overview ¶
TODO: Rename or/and break this package.
Index ¶
- Constants
- func AddressFromContext(ctx context.Context) string
- func CookiesFromIncomingContext(ctx context.Context) map[string]*http.Cookie
- func HTTPHeader(ctx context.Context, header string) string
- func HTTPMethod(ctx context.Context) string
- func HeaderMatcher(headers []string) func(string) (string, bool)
- func HttpMetadataAnnotator(_ context.Context, r *http.Request) metadata.MD
- func MethodOption(info *grpc.UnaryServerInfo, ext protoreflect.ExtensionType) (any, bool)
- func ParseCookies(headers ...string) map[string]*http.Cookie
- func SendCookie(ctx context.Context, cookie *http.Cookie) error
- func SendHeader(ctx context.Context, key, value string) error
- func SendStatusCode(ctx context.Context, code int) error
- func WithAddress(ctx context.Context, address string) context.Context
- type FieldOptionValue
Constants ¶
const ( // GRPC Metadata prefix that is added to allowed headers specified with // WithIncomingHeaders. MetadataHeaderPrefix = "pf-header-" // GRPC Metadata prefix that is added to metadata keys that are extracted from // the HTTP request. These keys will only be present for Gateway requests. MetadataHTTPPrefix = "pf-http-" )
Variables ¶
This section is empty.
Functions ¶
func AddressFromContext ¶
AddressFromContext returns the server's external address. This is the what links should reference, and likely points at a CDN or load balancer.
func CookiesFromIncomingContext ¶
CookiesFromIncomingContext reads a standard HTTP cookie header from the GRPC metadata and parses the contents.
func HTTPHeader ¶
HTTPHeader returns the value of a "permanent HTTP header" or a header that was added to the allow-list by a HeaderMatcher.
For permanent headers, see https://github.com/grpc-ecosystem/grpc-gateway/blob/main/runtime/context.go#L328
This will only ever return a value for requests coming via the GRPC Gateway.
func HTTPMethod ¶
HTTPMethod returns the HTTP method of the request that was made to the Gateway. This will only ever return a value for requests coming via the GRPC Gateway.
func HeaderMatcher ¶
HeaderMatcher appends the given headers to the allow-list for incoming requests. This is used to allow certain headers to be passed through the Gateway and into the GRPC server.
See: runtime.WithIncomingHeaderMatcher.
func HttpMetadataAnnotator ¶
HttpMetadataAnnotator is a gateway option that maps certain HTTP request fields to incoming GRPC metadata.
func MethodOption ¶
func MethodOption(info *grpc.UnaryServerInfo, ext protoreflect.ExtensionType) (any, bool)
MethodOption queries the value of a proto option for a GRPC method.
TODO: Consider creating an interceptor which injects the MethodDescriptor into the context. Then use methods which query options from the context, such that this can be used from both interceptors and handlers.
Example:
ok, value, err := MethodOption(info, SomeProto.E_Option)
func ParseCookies ¶
ParseCookies takes a cookie header string and returns a map of cookies.
func SendCookie ¶
SendCookie adds an http-set-cookie header for the provided cookie to the outgoing GRPC metadata.
func SendHeader ¶
SendHeader adds an http header to the outgoing GRPC metadata for forwarding.
func SendStatusCode ¶
SendStatusCode adds an http status code header to the outgoing GRPC metadata.
The GRPC Gateway will send this as the actual status code via the `statusCodeForwarder` function.
Types ¶
type FieldOptionValue ¶
func FieldOption ¶
func FieldOption(msg proto.Message, ext protoreflect.ExtensionType) ([]*FieldOptionValue, bool)
FieldOption queries a request proto and returns all fields which have the option set.