negotiation

package
v0.0.0-...-da7db65 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 License: Apache-2.0, Apache-2.0 Imports: 9 Imported by: 0

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 NegotiateOutputSerializer

func NegotiateOutputSerializer(req *http.Request, ns runtime.NegotiatedSerializer) (runtime.SerializerInfo, error)

NegotiateOutputSerializer returns a serializer for the output.

func NegotiateOutputStreamSerializer

func NegotiateOutputStreamSerializer(req *http.Request, ns runtime.NegotiatedSerializer) (runtime.SerializerInfo, error)

NegotiateOutputStreamSerializer returns a stream serializer for the given request.

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 AcceptedMediaType

type AcceptedMediaType struct {
	// Type is the first part of the media type ("application")
	Type string
	// SubType is the second part of the media type ("json")
	SubType string
	// Serializer is the serialization info this object accepts
	Serializer runtime.SerializerInfo
}

AcceptedMediaType contains information about a valid media type that the server can serialize.

func AcceptedMediaTypesForEndpoint

func AcceptedMediaTypesForEndpoint(ns runtime.NegotiatedSerializer) []AcceptedMediaType

AcceptedMediaTypesForEndpoint returns an array of structs that are used to efficiently check which allowed media types the server exposes.

type EndpointRestrictions

type EndpointRestrictions interface {
	// AllowsConversion should return true if the specified group version kind
	// is an allowed target object.
	AllowsConversion(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 *AcceptedMediaType
}

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

func NegotiateMediaTypeOptions

func NegotiateMediaTypeOptions(header string, accepted []AcceptedMediaType, 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