mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 03:57:41 +00:00
Return the correct set of supported mime types for non-streaming requests
This commit is contained in:
parent
5911f87dad
commit
7e33b12856
@ -61,7 +61,7 @@ func createHandler(r rest.NamedCreater, scope RequestScope, typer runtime.Object
|
|||||||
ctx = request.WithNamespace(ctx, namespace)
|
ctx = request.WithNamespace(ctx, namespace)
|
||||||
|
|
||||||
gv := scope.Kind.GroupVersion()
|
gv := scope.Kind.GroupVersion()
|
||||||
s, err := negotiation.NegotiateInputSerializer(req, scope.Serializer)
|
s, err := negotiation.NegotiateInputSerializer(req, false, scope.Serializer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
scope.err(err, w, req)
|
scope.err(err, w, req)
|
||||||
return
|
return
|
||||||
|
@ -60,7 +60,7 @@ func DeleteResource(r rest.GracefulDeleter, allowsOptions bool, scope RequestSco
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(body) > 0 {
|
if len(body) > 0 {
|
||||||
s, err := negotiation.NegotiateInputSerializer(req, metainternalversion.Codecs)
|
s, err := negotiation.NegotiateInputSerializer(req, false, metainternalversion.Codecs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
scope.err(err, w, req)
|
scope.err(err, w, req)
|
||||||
return
|
return
|
||||||
@ -228,7 +228,7 @@ func DeleteCollection(r rest.CollectionDeleter, checkBody bool, scope RequestSco
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(body) > 0 {
|
if len(body) > 0 {
|
||||||
s, err := negotiation.NegotiateInputSerializer(req, scope.Serializer)
|
s, err := negotiation.NegotiateInputSerializer(req, false, scope.Serializer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
scope.err(err, w, req)
|
scope.err(err, w, req)
|
||||||
return
|
return
|
||||||
|
@ -73,31 +73,30 @@ func NegotiateOutputStreamSerializer(req *http.Request, ns runtime.NegotiatedSer
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NegotiateInputSerializer returns the input serializer for the provided request.
|
// NegotiateInputSerializer returns the input serializer for the provided request.
|
||||||
func NegotiateInputSerializer(req *http.Request, ns runtime.NegotiatedSerializer) (runtime.SerializerInfo, error) {
|
func NegotiateInputSerializer(req *http.Request, streaming bool, ns runtime.NegotiatedSerializer) (runtime.SerializerInfo, error) {
|
||||||
mediaType := req.Header.Get("Content-Type")
|
mediaType := req.Header.Get("Content-Type")
|
||||||
return NegotiateInputSerializerForMediaType(mediaType, ns)
|
return NegotiateInputSerializerForMediaType(mediaType, streaming, ns)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NegotiateInputSerializerForMediaType returns the appropriate serializer for the given media type or an error.
|
// NegotiateInputSerializerForMediaType returns the appropriate serializer for the given media type or an error.
|
||||||
func NegotiateInputSerializerForMediaType(mediaType string, ns runtime.NegotiatedSerializer) (runtime.SerializerInfo, error) {
|
func NegotiateInputSerializerForMediaType(mediaType string, streaming bool, ns runtime.NegotiatedSerializer) (runtime.SerializerInfo, error) {
|
||||||
mediaTypes := ns.SupportedMediaTypes()
|
mediaTypes := ns.SupportedMediaTypes()
|
||||||
if len(mediaType) == 0 {
|
if len(mediaType) == 0 {
|
||||||
mediaType = mediaTypes[0].MediaType
|
mediaType = mediaTypes[0].MediaType
|
||||||
}
|
}
|
||||||
mediaType, _, err := mime.ParseMediaType(mediaType)
|
if mediaType, _, err := mime.ParseMediaType(mediaType); err == nil {
|
||||||
if err != nil {
|
|
||||||
_, supported := MediaTypesForSerializer(ns)
|
|
||||||
return runtime.SerializerInfo{}, NewUnsupportedMediaTypeError(supported)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, info := range mediaTypes {
|
for _, info := range mediaTypes {
|
||||||
if info.MediaType != mediaType {
|
if info.MediaType != mediaType {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_, supported := MediaTypesForSerializer(ns)
|
supported, streamingSupported := MediaTypesForSerializer(ns)
|
||||||
|
if streaming {
|
||||||
|
return runtime.SerializerInfo{}, NewUnsupportedMediaTypeError(streamingSupported)
|
||||||
|
}
|
||||||
return runtime.SerializerInfo{}, NewUnsupportedMediaTypeError(supported)
|
return runtime.SerializerInfo{}, NewUnsupportedMediaTypeError(supported)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ func UpdateResource(r rest.Updater, scope RequestScope, typer runtime.ObjectType
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s, err := negotiation.NegotiateInputSerializer(req, scope.Serializer)
|
s, err := negotiation.NegotiateInputSerializer(req, false, scope.Serializer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
scope.err(err, w, req)
|
scope.err(err, w, req)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user