negotiation

package
v0.0.0-...-b2a8ad6 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 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

func NewNotAcceptableError(accepted []string) error

func NewUnsupportedMediaTypeError

func NewUnsupportedMediaTypeError(accepted []string) error

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.

Jump to

Keyboard shortcuts

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