gateway

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const MetadataHeaderPrefix = "Grpc-Metadata-"

MetadataHeaderPrefix is the http prefix that represents custom metadata parameters to or from a gRPC call.

View Source
const MetadataPrefix = "grpcgateway-"

MetadataPrefix is prepended to permanent HTTP header keys (as specified by the IANA) when added to the gRPC context.

View Source
const MetadataTrailerPrefix = "Grpc-Trailer-"

MetadataTrailerPrefix is prepended to gRPC metadata as it is converted to HTTP headers in a response handled by grpc-gateway

Variables

View Source
var DefaultContextTimeout = 0 * time.Second

DefaultContextTimeout is used for gRPC call context.WithTimeout whenever a Grpc-Timeout inbound header isn't present. If the value is 0 the sent `context` will not have a timeout.

Functions

func AnnotateContext

func AnnotateContext(ctx context.Context, mux *ServeMux, req *http.Request, rpcMethodName string, options ...AnnotateContextOption) (context.Context, error)

AnnotateContext adds context information such as metadata from the request.

At a minimum, the RemoteAddr is included in the fashion of "X-Forwarded-For", except that the forwarded destination is not another HTTP service but rather a gRPC service.

func AnnotateIncomingContext

func AnnotateIncomingContext(ctx context.Context, mux *ServeMux, req *http.Request, rpcMethodName string, options ...AnnotateContextOption) (context.Context, error)

AnnotateIncomingContext adds context information such as metadata from the request. Attach metadata as incoming context.

func DefaultHTTPErrorHandler

func DefaultHTTPErrorHandler(ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, r *http.Request, err error)

DefaultHTTPErrorHandler is the default error handler. If "err" is a gRPC Status, the function replies with the status code mapped by HTTPStatusFromCode. If "err" is a HTTPStatusError, the function replies with the status code provide by that struct. This is intended to allow passing through of specific statuses via the function set via WithRoutingErrorHandler for the ServeMux constructor to handle edge cases which the standard mappings in HTTPStatusFromCode are insufficient for. If otherwise, it replies with http.StatusInternalServerError.

The response body written by this function is a Status message marshaled by the Marshaler.

func DefaultHeaderMatcher

func DefaultHeaderMatcher(key string) (string, bool)

DefaultHeaderMatcher is used to pass http request headers to/from gRPC context. This adds permanent HTTP header keys (as specified by the IANA, e.g: Accept, Cookie, Host) to the gRPC metadata with the grpcgateway- prefix. If you want to know which headers are considered permanent, you can view the isPermanentHTTPHeader function. HTTP headers that start with 'Grpc-Metadata-' are mapped to gRPC metadata after removing the prefix 'Grpc-Metadata-'. Other headers are not added to the gRPC metadata.

func DefaultRoutingErrorHandler

func DefaultRoutingErrorHandler(
	ctx context.Context, mux *ServeMux, marshaler Marshaler, w http.ResponseWriter, r *http.Request, err ErrRouting)

DefaultRoutingErrorHandler is our default handler for routing errors. By default http error codes mapped on the following error codes:

NotFound -> grpc.NotFound
StatusBadRequest -> grpc.InvalidArgument
MethodNotAllowed -> grpc.Unimplemented
Other -> grpc.Internal, method is not expecting to be called for anything else

func DefaultStreamErrorHandler

func DefaultStreamErrorHandler(_ context.Context, _ *http.Request, err error) (int, any)

func DefaultWebsocketErrorHandler

func DefaultWebsocketErrorHandler(
	ctx context.Context, marshaler Marshaler, _ *http.Request, connection websocket.Connection, err error)

func HTTPPathPattern

func HTTPPathPattern(ctx context.Context) (string, bool)

HTTPPathPattern returns the HTTP path pattern string relating to the HTTP handler, if one exists. The format of the returned string is defined by the google.api.http path template type.

func HTTPStatusFromCode

func HTTPStatusFromCode(code codes.Code) int

HTTPStatusFromCode converts a gRPC error code into the corresponding HTTP response status. See: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto

func NewServerMetadataContext

func NewServerMetadataContext(ctx context.Context, md ServerMetadata) context.Context

NewServerMetadataContext creates a new context with ServerMetadata

func RPCMethod

func RPCMethod(ctx context.Context) (string, bool)

RPCMethod returns the method string for the server context. The returned string is in the format of "/package.service/method".

Types

type AnnotateContextOption

type AnnotateContextOption func(ctx context.Context) context.Context

func WithHTTPPathPattern

func WithHTTPPathPattern(pattern string) AnnotateContextOption

type Decoder

type Decoder = protomarshal.Decoder

Decoder decodes a byte sequence

type DecoderFunc

type DecoderFunc = protomarshal.DecoderFunc

DecoderFunc adapts an decoder function into Decoder.

type DefaultQueryParser

type DefaultQueryParser struct{}

DefaultQueryParser is a QueryParameterParser which implements the default query parameters parsing behavior.

func (*DefaultQueryParser) Parse

Parse populates "values" into "msg". A value is ignored if its key starts with one of the elements in "filter".

type Delimited

type Delimited = protomarshal.Delimited

Delimited defines the streaming delimiter.

type Encoder

type Encoder = protomarshal.Encoder

Encoder encodes gRPC payloads / fields into byte sequence.

type EncoderFunc

type EncoderFunc = protomarshal.EncoderFunc

EncoderFunc adapts an encoder function into Encoder

type ErrInvalidQueryParameters

type ErrInvalidQueryParameters struct {
	// Err is the underlying parsing error.
	Err error
}

ErrInvalidQueryParameters is the error related to parsing query params. If the query parameters are invalid, cannot be parsed or their values cannot be parsed, this error type gets used.

func (ErrInvalidQueryParameters) Error

func (ErrInvalidQueryParameters) GRPCStatus

func (e ErrInvalidQueryParameters) GRPCStatus() *status.Status

type ErrMarshal

type ErrMarshal struct {
	// Err is the underlying marshal/unmarshal error.
	Err error
	// Inbound indicates whether or not the error is from unmarshaling an inbound request payload.
	//
	// If this value is true, it indicates that the request payload could not be unmarshaled
	// into the expected gRPC request type.
	//
	// If this value is false, it indicates the marshaler failed to encode response payload when
	// forwarding the response back to the HTTP client.
	Inbound bool
}

ErrMarshal is the error returned by the gateway when marshal or unmarshal functions fail.

func (ErrMarshal) Error

func (e ErrMarshal) Error() string

func (ErrMarshal) GRPCStatus

func (e ErrMarshal) GRPCStatus() *status.Status

type ErrPathParameterInvalidEnum

type ErrPathParameterInvalidEnum struct {
	// Err is the underlying parsing error.
	Err error
	// Name is the name of the parameter that happens to be a field path in the proto type.
	Name string
}

ErrPathParameterInvalidEnum is the error generated when parsing values path parameters to an enum type fails.

func (ErrPathParameterInvalidEnum) Error

func (ErrPathParameterInvalidEnum) GRPCStatus

func (e ErrPathParameterInvalidEnum) GRPCStatus() *status.Status

type ErrPathParameterMissing

type ErrPathParameterMissing struct {
	// Name is the name of the parameter that happens to be a field path in the proto type.
	Name string
}

ErrPathParameterMissing is the error generated by the gateway when HTTP path parameters are missing.

func (ErrPathParameterMissing) Error

func (e ErrPathParameterMissing) Error() string

func (ErrPathParameterMissing) GRPCStatus

func (e ErrPathParameterMissing) GRPCStatus() *status.Status

type ErrPathParameterTypeMismatch

type ErrPathParameterTypeMismatch struct {
	// Err is the underlying type mismatch.
	Err error
	// Name is the name of the parameter that happens to be a field path in the proto type.
	Name string
}

ErrPathParameterTypeMismatch is the error generated by the gateway when path parameter type is unexpected.

func (ErrPathParameterTypeMismatch) Error

func (ErrPathParameterTypeMismatch) GRPCStatus

func (e ErrPathParameterTypeMismatch) GRPCStatus() *status.Status

type ErrRouting

type ErrRouting uint8

ErrRouting is an error type specific to routing errors such as not found and method not allowed.

const (
	// ErrRoutingMethodNotAllowed is for routes that exist but with a different HTTP method.
	ErrRoutingMethodNotAllowed ErrRouting = iota
	// ErrRoutingNotFound is for routes that are not handled by the serve mux.
	ErrRoutingNotFound
)

func (ErrRouting) Error

func (r ErrRouting) Error() string

func (ErrRouting) GRPCStatus

func (r ErrRouting) GRPCStatus() *status.Status

type ErrStreamingMethodNotAllowed

type ErrStreamingMethodNotAllowed struct {
	// MethodSupportsWebsocket indicates whether or not the server accepts websocket for this method.
	MethodSupportsWebsocket bool
	// MethodSupportsSSE indicates whether or not the server accepts SSE for this method.
	MethodSupportsSSE bool
	// MethodSupportsChunkedTransfer indicates whether or not the server accepts chunked transfer streaming.
	MethodSupportsChunkedTransfer bool
}

ErrStreamingMethodNotAllowed is the error related to when a server receives a request that does not use any of the available streaming methods.

func (ErrStreamingMethodNotAllowed) Error

func (ErrStreamingMethodNotAllowed) GRPCStatus

func (e ErrStreamingMethodNotAllowed) GRPCStatus() *status.Status

type ErrorHandlerFunc

type ErrorHandlerFunc func(context.Context, *ServeMux, Marshaler, http.ResponseWriter, *http.Request, error)

ErrorHandlerFunc is the signature used to configure error handling.

type ForwardResponseFunc

type ForwardResponseFunc func(context.Context, http.ResponseWriter, proto.Message) error

ForwardResponseFunc updates the outgoing gRPC request and the HTTP response.

type HTTPStatusError

type HTTPStatusError struct {
	HTTPStatus int
	Err        error
}

HTTPStatusError is the error to use when needing to provide a different HTTP status code for an error passed to the DefaultRoutingErrorHandler.

func (HTTPStatusError) Error

func (e HTTPStatusError) Error() string

type HeaderMatcherFunc

type HeaderMatcherFunc func(string) (string, bool)

HeaderMatcherFunc checks whether a header key should be forwarded to/from gRPC context.

type Marshaler

type Marshaler = protomarshal.Marshaler

Marshaler defines a conversion between byte sequence and gRPC payloads / fields.

type MetadataAnnotatorFunc

type MetadataAnnotatorFunc func(context.Context, *http.Request) metadata.MD

MetadataAnnotatorFunc updates the outgoing gRPC request context based on the incoming HTTP request.

type PanicHandlerFunc

type PanicHandlerFunc func(http.ResponseWriter, *http.Request, interface{})

PanicHandlerFunc is a function that gets called when a panic is encountered.

type Params

type Params = httprouter.Params

type ProtoMessage

type ProtoMessage interface {
	proto.Message
	Reset()
}

type QueryParameterParseOptions

type QueryParameterParseOptions struct {
	// Filter holds a trie that can block already bound or otherwise ignored query paramters.
	Filter *trie.Node

	// Aliases is a table of arbitrary names mapped to field keys.
	Aliases map[string]string

	// LimitToAliases limits the query parameters to aliases only. Used when auto discovery is disabled.
	LimitToAliases bool
}

QueryParameterParseOptions hold all inputs for parsing query parameters.

type QueryParameterParser

type QueryParameterParser interface {
	Parse(msg proto.Message, values url.Values, inputs QueryParameterParseOptions) error
}

QueryParameterParser defines interface for all query parameter parsers.

type RoutingErrorHandlerFunc

type RoutingErrorHandlerFunc func(context.Context, *ServeMux, Marshaler, http.ResponseWriter, *http.Request, ErrRouting)

RoutingErrorHandlerFunc is the signature used to configure error handling for routing errors.

type SSEConfig

type SSEConfig struct {
	// EndOfStreamMessage is the last message send when the gRPC client streaming finishes.
	EndOfStreamMessage *SSEMessage
}

SSEConfig configures the behavior of the Server-Sent Events (SSE).

type SSEErrorHandlerFunc

type SSEErrorHandlerFunc func(context.Context, Marshaler, *http.Request, error) *SSEMessage

SSEErrorHandlerFunc is the signature used to configure SSE error handling.

This function should return desired SSE message for the error response. If the returned message is nil, no response is sent.

type SSEMessage

type SSEMessage struct {
	// ID is the event ID (optional).
	ID string

	// Event is the event portion of the SSE message (optional).
	Event string

	// Data is the event data.
	// Must be UTF-8 encoded.
	Data []byte
}

SSEMessage describes a single Server-Sent Events (SSE) message.

See: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#event_stream_format

func DefaultSSEErrorHandler

func DefaultSSEErrorHandler(_ context.Context, marshaler Marshaler, _ *http.Request, err error) *SSEMessage

type ServeMux

type ServeMux struct {
	// contains filtered or unexported fields
}

ServeMux is a request multiplexer for grpc-gateway. It matches http requests to patterns and invokes the corresponding handler.

func NewServeMux

func NewServeMux(opts ...ServeMuxOption) *ServeMux

NewServeMux returns a new ServeMux whose internal mapping is empty.

func (*ServeMux) ForwardResponseMessage

func (s *ServeMux) ForwardResponseMessage(
	ctx context.Context,
	marshaler Marshaler,
	writer http.ResponseWriter,
	req *http.Request,
	receivedResponse proto.Message)

func (*ServeMux) ForwardResponseStreamChunked

func (s *ServeMux) ForwardResponseStreamChunked(
	ctx context.Context,
	marshaler Marshaler,
	writer http.ResponseWriter,
	req *http.Request,
	recv func() (proto.Message, error))

ForwardResponseStreamChunked forwards the stream from gRPC server to REST client using Transfer-Encoding chunked.

func (*ServeMux) ForwardResponseStreamSSE

func (s *ServeMux) ForwardResponseStreamSSE(
	ctx context.Context,
	marshaler Marshaler,
	writer http.ResponseWriter,
	req *http.Request,
	recv func() (proto.Message, error))

ForwardResponseStreamSSE forwards the stream from gRPC server to REST client using Server-Sent Events (SSE).

func (*ServeMux) ForwardWebsocket

func (s *ServeMux) ForwardWebsocket(
	ctx context.Context,
	req *http.Request, stream grpc.ClientStream, ws websocket.Connection,
	inboundMarshaler, outboundMarshaler Marshaler,
	protoReq, protoRes ProtoMessage)

func (*ServeMux) ForwardWebsocketServerStreaming

func (s *ServeMux) ForwardWebsocketServerStreaming(
	ctx context.Context,
	req *http.Request, stream grpc.ClientStream, ws websocket.Connection,
	outboundMarshaler Marshaler,
	protoRes ProtoMessage)

func (*ServeMux) HTTPError

func (s *ServeMux) HTTPError(
	ctx context.Context, marshaler Marshaler, w http.ResponseWriter, r *http.Request, err error)

HTTPError uses the mux-configured error handler.

func (*ServeMux) Handle

func (s *ServeMux) Handle(method, pattern string, handler http.Handler)

Handle registers a new handler for the method and pattern specified.

func (*ServeMux) HandleWithParams

func (s *ServeMux) HandleWithParams(method, pattern string, handler httprouter.Handle)

HandleWithParams registers a new handler for the method and pattern specified.

NOTE: this method takes an httprouter.Handle function, helpful when path parameters are needed. if using http.Handler is desired, use Handle instead.

func (*ServeMux) IsSSE

func (s *ServeMux) IsSSE(req *http.Request) bool

IsSSE returns whether or not client accepts event streams.

func (*ServeMux) IsWebsocketUpgrade

func (s *ServeMux) IsWebsocketUpgrade(req *http.Request) bool

IsWebsocketUpgrade returns whether or not the client is requesting for connection upgrade to websocket and server is capable of upgrading. If websocket upgrade function is not setup, this method returns false.

func (*ServeMux) MarshalerForRequest

func (s *ServeMux) MarshalerForRequest(req *http.Request) (inbound, outbound Marshaler)

MarshalerForRequest returns the inbound/outbound marshalers for this request. It checks the registry on the ServeMux for the MIME type set by the Content-Type header. If it isn't set (or the request Content-Type is empty), checks for "*". If there are multiple Content-Type headers set, choose the first one that it can exactly match in the registry. Otherwise, it follows the above logic for "*"/InboundMarshaler/OutboundMarshaler.

func (*ServeMux) PopulateQueryParameters

func (s *ServeMux) PopulateQueryParameters(msg proto.Message, values url.Values, inputs QueryParameterParseOptions) error

PopulateQueryParameters parses query parameters into "msg" using current query parser.

func (*ServeMux) ServeHTTP

func (s *ServeMux) ServeHTTP(writer http.ResponseWriter, req *http.Request)

ServeHTTP dispatches the request to the first handler whose pattern matches to r.Method and r.URL.Path.

func (*ServeMux) UpgradeToWebsocket

func (s *ServeMux) UpgradeToWebsocket(response http.ResponseWriter, req *http.Request) (websocket.Connection, error)

UpgradeToWebsocket upgrades an HTTP request to a websocket connection.

func (*ServeMux) WebsocketError

func (s *ServeMux) WebsocketError(
	ctx context.Context, marshaler Marshaler, r *http.Request, c websocket.Connection, err error)

WebsocketError uses the mux-configured websocket error handler.

type ServeMuxOption

type ServeMuxOption interface {
	// contains filtered or unexported methods
}

ServeMuxOption is an option that can be given to a ServeMux on construction.

func WithDisablePathLengthFallback

func WithDisablePathLengthFallback() ServeMuxOption

WithDisablePathLengthFallback returns a ServeMuxOption for disable path length fallback.

func WithErrorHandler

func WithErrorHandler(fn ErrorHandlerFunc) ServeMuxOption

WithErrorHandler returns a ServeMuxOption for configuring a custom error handler.

This can be used to configure a custom error response.

func WithForwardResponseOption

func WithForwardResponseOption(forwardResponseOption ForwardResponseFunc) ServeMuxOption

WithForwardResponseOption returns a ServeMuxOption representing the forwardResponseOption.

forwardResponseOption is an option that will be called on the relevant context.Context, http.ResponseWriter, and proto.Message before every forwarded response.

The message may be nil in the case where just a header is being sent.

func WithGlobalOptionsHandler

func WithGlobalOptionsHandler(handler http.Handler) ServeMuxOption

WithGlobalOptionsHandler sets an optional handler that is called on automatic OPTIONS requests. The handler is only called if handling OPTIONS is enabled and no OPTIONS handler for the specific path is set. The "Allowed" header is set before calling the handler.

func WithHealthEndpointAt

func WithHealthEndpointAt(healthCheckClient grpc_health_v1.HealthClient, endpointPath string) ServeMuxOption

WithHealthEndpointAt returns a ServeMuxOption that will add an endpoint to the created ServeMux at the path specified by endpointPath. When called the handler will forward the request to the upstream grpc service health check (defined in the gRPC Health Checking Protocol).

If you define a service as query parameter, this will also be forwarded as service in the HealthCheckRequest.

func WithHealthzEndpoint

func WithHealthzEndpoint(healthCheckClient grpc_health_v1.HealthClient) ServeMuxOption

WithHealthzEndpoint returns a ServeMuxOption that will add a /healthz endpoint to the created ServeMux.

See WithHealthEndpointAt for the general implementation.

func WithIncomingHeaderMatcher

func WithIncomingHeaderMatcher(fn HeaderMatcherFunc) ServeMuxOption

WithIncomingHeaderMatcher returns a ServeMuxOption representing a headerMatcher for incoming request to gateway.

This matcher will be called with each header in http.Request. If matcher returns true, that header will be passed to gRPC context. To transform the header before passing to gRPC context, matcher should return modified header.

func WithMetadata

func WithMetadata(annotator MetadataAnnotatorFunc) ServeMuxOption

WithMetadata returns a ServeMuxOption for passing metadata to a gRPC context.

This can be used by services that need to read from http.Request and modify gRPC context. A common use case is reading token from cookie and adding it in gRPC context.

func WithMethodNotAllowedHandler

func WithMethodNotAllowedHandler(handler http.Handler) ServeMuxOption

WithMethodNotAllowedHandler sets a configurable http.Handler which is called when a request cannot be routed and HandleMethodNotAllowed is true. If it is not set, http.Error with http.StatusMethodNotAllowed is used. The "Allow" header with allowed request methods is set before the handler is called.

func WithNotFoundHandler

func WithNotFoundHandler(handler http.Handler) ServeMuxOption

WithNotFoundHandler sets a configurable http.Handler which is called when no matching route is found. If it is not set, http.NotFound is used.

func WithOutgoingHeaderMatcher

func WithOutgoingHeaderMatcher(fn HeaderMatcherFunc) ServeMuxOption

WithOutgoingHeaderMatcher returns a ServeMuxOption representing a headerMatcher for outgoing response from gateway.

This matcher will be called with each header in response header metadata. If matcher returns true, that header will be passed to http response returned from gateway. To transform the header before passing to response, matcher should return modified header.

func WithPanicHandler

func WithPanicHandler(handler PanicHandlerFunc) ServeMuxOption

WithPanicHandler sets the function to handle panics recovered from http handlers. It should be used to generate a error page and return the http error code 500 (Internal Server Error). The handler can be used to keep your server from crashing because of unrecovered panics.

func WithQueryParameterParser

func WithQueryParameterParser(queryParameterParser QueryParameterParser) ServeMuxOption

WithQueryParameterParser sets the query parameter parser, used to populate message from query parameters. Configuring this will mean the generated OpenAPI output is no longer correct, and it should be done with careful consideration.

func WithRoutingErrorHandler

func WithRoutingErrorHandler(fn RoutingErrorHandlerFunc) ServeMuxOption

WithRoutingErrorHandler returns a ServeMuxOption for configuring a custom error handler to handle http routing errors.

Method called for errors which can happen before gRPC route selected or executed. The following error codes: StatusMethodNotAllowed StatusNotFound StatusBadRequest

func WithSSEConfig

func WithSSEConfig(config SSEConfig) ServeMuxOption

WithSSEConfig sets Server-Sent Events (SSE) configuration.

func WithSSEErrorHandler

func WithSSEErrorHandler(handler SSEErrorHandlerFunc) ServeMuxOption

WithSSEErrorHandler returns a ServeMuxOption for configuring an SSE error handler.

This can be used to configure a custom error response.

func WithStreamErrorHandler

func WithStreamErrorHandler(fn StreamErrorHandlerFunc) ServeMuxOption

WithStreamErrorHandler returns a ServeMuxOption that will use the given custom stream error handler, which allows for customizing the error trailer for server-streaming calls.

For stream errors that occur before any response has been written, the mux's ErrorHandler will be invoked. However, once data has been written, the errors must be handled differently: they must be included in the response body. The response body's final message will include the error details returned by the stream error handler.

func WithWebsocketErrorHandler

func WithWebsocketErrorHandler(fn WebsocketErrorHandlerFunc) ServeMuxOption

WithWebsocketErrorHandler returns a ServeMuxOption for configuring a websocket error handler.

This can be used to configure a custom error response.

func WithWebsocketUpgrader

func WithWebsocketUpgrader(upgradeFunc WebsocketUpgradeFunc) ServeMuxOption

WithWebsocketUpgrader enables websocket upgrades for the serve mux.

func WithoutHandlingOptions

func WithoutHandlingOptions() ServeMuxOption

WithoutHandlingOptions disabled automatically handling OPTIONS for available endpoints, which is by default enabled.

type ServerMetadata

type ServerMetadata struct {
	HeaderMD  metadata.MD
	TrailerMD metadata.MD
}

ServerMetadata consists of metadata sent from gRPC server.

func ServerMetadataFromContext

func ServerMetadataFromContext(ctx context.Context) (md ServerMetadata, ok bool)

ServerMetadataFromContext returns the ServerMetadata in ctx

type ServerTransportStream

type ServerTransportStream struct {
	// contains filtered or unexported fields
}

ServerTransportStream implements grpc.ServerTransportStream. It should only be used by the generated files to support grpc.SendHeader outside of gRPC server use.

func (*ServerTransportStream) Header

func (s *ServerTransportStream) Header() metadata.MD

Header returns the header metadata of the stream.

func (*ServerTransportStream) Method

func (s *ServerTransportStream) Method() string

Method returns the method for the stream.

func (*ServerTransportStream) SendHeader

func (s *ServerTransportStream) SendHeader(md metadata.MD) error

SendHeader sets the header metadata.

func (*ServerTransportStream) SetHeader

func (s *ServerTransportStream) SetHeader(md metadata.MD) error

SetHeader sets the header metadata.

func (*ServerTransportStream) SetTrailer

func (s *ServerTransportStream) SetTrailer(md metadata.MD) error

SetTrailer sets the trailer metadata.

func (*ServerTransportStream) Trailer

func (s *ServerTransportStream) Trailer() metadata.MD

Trailer returns the cached trailer metadata.

type StreamErrorHandlerFunc

type StreamErrorHandlerFunc func(context.Context, *http.Request, error) (httpStatus int, data any)

StreamErrorHandlerFunc is the signature used to configure stream error handling.

This function should return desired HTTP status code for the response and any object. The status would be used only if status has not already been written. The data is flexible format and will be unmarshaled using the marshaler for the request. If the returning data is nil, no data will be written.

This is used for chunked transfer only.

type WebsocketErrorHandlerFunc

type WebsocketErrorHandlerFunc func(context.Context, Marshaler, *http.Request, websocket.Connection, error)

WebsocketErrorHandlerFunc is the signature used to configure websocket error handling.

This function should return desired error message that will get marshaled and sent back to the client before closing the connection.

If the returned data is nil, no message is sent back before closing the connection.

type WebsocketUpgradeFunc

type WebsocketUpgradeFunc func(http.ResponseWriter, *http.Request) (websocket.Connection, error)

WebsocketUpgradeFunc handles a protocol upgrade and creates a websocket connection.

Jump to

Keyboard shortcuts

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