negotiation

package
v0.29.3 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: Apache-2.0 Imports: 9 Imported by: 117

Documentation

Overview

Package negotiation contains media type negotiation logic.

Index

Constants

This section is empty.

Variables

View Source
var DefaultEndpointRestrictions = emptyEndpointRestrictions{}

DefaultEndpointRestrictions is the default EndpointRestrictions which allows content-type negotiation to verify server support for specific options

Functions

func MediaTypesForSerializer

func MediaTypesForSerializer(ns runtime.NegotiatedSerializer) (mediaTypes, streamMediaTypes []string)

MediaTypesForSerializer returns a list of media and stream media types for the server.

func NegotiateInputSerializer

func NegotiateInputSerializer(req *http.Request, streaming bool, ns runtime.NegotiatedSerializer) (runtime.SerializerInfo, error)

NegotiateInputSerializer returns the input serializer for the provided request.

func NegotiateInputSerializerForMediaType

func NegotiateInputSerializerForMediaType(mediaType string, streaming bool, ns runtime.NegotiatedSerializer) (runtime.SerializerInfo, error)

NegotiateInputSerializerForMediaType returns the appropriate serializer for the given media type or an error.

func NegotiateOutputMediaTypeStream

func NegotiateOutputMediaTypeStream(req *http.Request, ns runtime.NegotiatedSerializer, restrictions EndpointRestrictions) (runtime.SerializerInfo, error)

NegotiateOutputMediaTypeStream returns a stream serializer for the given request.

func NewNotAcceptableConversionError

func NewNotAcceptableConversionError(target string, accepted []string) error

NewNotAcceptableConversionError returns an error indicating that the desired API transformation to the target group version kind string is not accepted and only the listed mime types are allowed. This is temporary while Table does not yet support protobuf encoding.

func NewNotAcceptableError

func NewNotAcceptableError(accepted []string) error

NewNotAcceptableError returns an error of NotAcceptable which contains specified string

func NewUnsupportedMediaTypeError

func NewUnsupportedMediaTypeError(accepted []string) error

NewUnsupportedMediaTypeError returns an error of UnsupportedMediaType which contains specified string

Types

type EndpointRestrictions

type EndpointRestrictions interface {
	// AllowsMediaTypeTransform returns true if the endpoint allows either the requested mime type
	// or the requested transformation. If false, the caller should ignore this mime type. If the
	// target is nil, the client is not requesting a transformation.
	AllowsMediaTypeTransform(mimeType, mimeSubType string, target *schema.GroupVersionKind) bool
	// AllowsServerVersion should return true if the specified version is valid
	// for the server group.
	AllowsServerVersion(version string) bool
	// AllowsStreamSchema should return true if the specified stream schema is
	// valid for the server group.
	AllowsStreamSchema(schema string) bool
}

EndpointRestrictions is an interface that allows content-type negotiation to verify server support for specific options

type MediaTypeOptions

type MediaTypeOptions struct {
	// pretty is true if the requested representation should be formatted for human
	// viewing
	Pretty bool

	// stream, if set, indicates that a streaming protocol variant of this encoding
	// is desired. The only currently supported value is watch which returns versioned
	// events. In the future, this may refer to other stream protocols.
	Stream string

	// convert is a request to alter the type of object returned by the server from the
	// normal response
	Convert *schema.GroupVersionKind
	// useServerVersion is an optional version for the server group
	UseServerVersion string

	// export is true if the representation requested should exclude fields the server
	// has set
	Export bool

	// unrecognized is a list of all unrecognized keys
	Unrecognized []string

	// the accepted media type from the client
	Accepted runtime.SerializerInfo
}

MediaTypeOptions describes information for a given media type that may alter the server response

func NegotiateMediaTypeOptions

func NegotiateMediaTypeOptions(header string, accepted []runtime.SerializerInfo, endpoint EndpointRestrictions) (MediaTypeOptions, bool)

NegotiateMediaTypeOptions returns the most appropriate content type given the accept header and a list of alternatives along with the accepted media type parameters.

func NegotiateOutputMediaType

func NegotiateOutputMediaType(req *http.Request, ns runtime.NegotiatedSerializer, restrictions EndpointRestrictions) (MediaTypeOptions, runtime.SerializerInfo, error)

NegotiateOutputMediaType negotiates the output structured media type and a serializer, or returns an error.

Jump to

Keyboard shortcuts

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