From 4d1a57003c2015ec6289977d97ea0747e63f4804 Mon Sep 17 00:00:00 2001 From: Robert Coup Date: Fri, 6 May 2022 14:10:16 +0100 Subject: [PATCH] lfshttp: fix invalid Accept header syntax Previously we were using the same value for both the HTTP request Content-Type header (which includes a charset), and the Accept header, where charset is not part of the valid syntax. Split them out into separate values. --- lfshttp/client.go | 5 +++-- locking/api_test.go | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lfshttp/client.go b/lfshttp/client.go index 1d5ecb8f..ee6cccb8 100644 --- a/lfshttp/client.go +++ b/lfshttp/client.go @@ -27,7 +27,8 @@ import ( "golang.org/x/net/http2" ) -const MediaType = "application/vnd.git-lfs+json; charset=utf-8" +const MediaType = "application/vnd.git-lfs+json" +const RequestContentType = MediaType + "; charset=utf-8" var ( UserAgent = "git-lfs" @@ -148,7 +149,7 @@ hint: without the API server" in custom-transfers.md for details.`), "\n") if merr := MarshalToRequest(req, body); merr != nil { return req, merr } - req.Header.Set("Content-Type", MediaType) + req.Header.Set("Content-Type", RequestContentType) } return req, err diff --git a/locking/api_test.go b/locking/api_test.go index d0ced3f6..33e0bdbf 100644 --- a/locking/api_test.go +++ b/locking/api_test.go @@ -30,7 +30,7 @@ func TestAPILock(t *testing.T) { assert.Equal(t, "POST", r.Method) assert.Equal(t, lfshttp.MediaType, r.Header.Get("Accept")) - assert.Equal(t, lfshttp.MediaType, r.Header.Get("Content-Type")) + assert.Equal(t, lfshttp.RequestContentType, r.Header.Get("Content-Type")) assert.Equal(t, "53", r.Header.Get("Content-Length")) reqLoader, body := gojsonschema.NewReaderLoader(r.Body) @@ -80,7 +80,7 @@ func TestAPIUnlock(t *testing.T) { assert.Equal(t, "POST", r.Method) assert.Equal(t, lfshttp.MediaType, r.Header.Get("Accept")) - assert.Equal(t, lfshttp.MediaType, r.Header.Get("Content-Type")) + assert.Equal(t, lfshttp.RequestContentType, r.Header.Get("Content-Type")) reqLoader, body := gojsonschema.NewReaderLoader(r.Body) unlockReq := &unlockRequest{} @@ -182,7 +182,7 @@ func TestAPISearchVerifiable(t *testing.T) { assert.Equal(t, "POST", r.Method) assert.Equal(t, lfshttp.MediaType, r.Header.Get("Accept")) - assert.Equal(t, lfshttp.MediaType, r.Header.Get("Content-Type")) + assert.Equal(t, lfshttp.RequestContentType, r.Header.Get("Content-Type")) body := lockVerifiableRequest{} if assert.Nil(t, json.NewDecoder(r.Body).Decode(&body)) {