negotiation

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2017 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package negotation contains media type negotiation logic.

Index

Constants

This section is empty.

Variables

View Source
var DefaultEndpointRestrictions = emptyEndpointRestrictions{}

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 NegotiateOutputStreamSerializer

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

func NewNotAcceptableError added in v1.7.0

func NewNotAcceptableError(accepted []string) error

func NewUnsupportedMediaTypeError added in v1.7.0

func NewUnsupportedMediaTypeError(accepted []string) error

Types

type AcceptedMediaType added in v1.7.0

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 added in v1.7.0

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 added in v1.7.0

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 added in v1.7.0

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 added in v1.7.0

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 added in v1.7.0

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

Jump to

Keyboard shortcuts

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