apiserver: Fix handling patch requests with charset

Fixes #14872
This commit is contained in:
Derek Parker
2015-09-30 14:03:27 -07:00
parent bd8ee1c4c4
commit 4745cc9d9a
2 changed files with 6 additions and 1 deletions

View File

@@ -1659,7 +1659,7 @@ func TestPatch(t *testing.T) {
client := http.Client{}
request, err := http.NewRequest("PATCH", server.URL+"/api/version/namespaces/default/simple/"+ID, bytes.NewReader([]byte(`{"labels":{"foo":"bar"}}`)))
request.Header.Set("Content-Type", "application/merge-patch+json")
request.Header.Set("Content-Type", "application/merge-patch+json; charset=UTF-8")
_, err = client.Do(request)
if err != nil {
t.Errorf("unexpected error: %v", err)

View File

@@ -21,6 +21,7 @@ import (
"net/http"
"net/url"
gpath "path"
"strings"
"time"
"k8s.io/kubernetes/pkg/admission"
@@ -736,6 +737,10 @@ func setListSelfLink(obj runtime.Object, req *restful.Request, namer ScopeNamer)
}
func getPatchedJS(contentType string, originalJS, patchJS []byte, obj runtime.Object) ([]byte, error) {
// Remove "; charset=" if included in header.
if idx := strings.Index(contentType, ";"); idx > 0 {
contentType = contentType[:idx]
}
patchType := api.PatchType(contentType)
switch patchType {
case api.JSONPatchType: