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.
This commit is contained in:
Robert Coup 2022-05-06 14:10:16 +01:00
parent 2e63adeed5
commit 4d1a57003c
2 changed files with 6 additions and 5 deletions

@ -27,7 +27,8 @@ import (
"golang.org/x/net/http2" "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 ( var (
UserAgent = "git-lfs" 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 { if merr := MarshalToRequest(req, body); merr != nil {
return req, merr return req, merr
} }
req.Header.Set("Content-Type", MediaType) req.Header.Set("Content-Type", RequestContentType)
} }
return req, err return req, err

@ -30,7 +30,7 @@ func TestAPILock(t *testing.T) {
assert.Equal(t, "POST", r.Method) assert.Equal(t, "POST", r.Method)
assert.Equal(t, lfshttp.MediaType, r.Header.Get("Accept")) 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")) assert.Equal(t, "53", r.Header.Get("Content-Length"))
reqLoader, body := gojsonschema.NewReaderLoader(r.Body) reqLoader, body := gojsonschema.NewReaderLoader(r.Body)
@ -80,7 +80,7 @@ func TestAPIUnlock(t *testing.T) {
assert.Equal(t, "POST", r.Method) assert.Equal(t, "POST", r.Method)
assert.Equal(t, lfshttp.MediaType, r.Header.Get("Accept")) 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) reqLoader, body := gojsonschema.NewReaderLoader(r.Body)
unlockReq := &unlockRequest{} unlockReq := &unlockRequest{}
@ -182,7 +182,7 @@ func TestAPISearchVerifiable(t *testing.T) {
assert.Equal(t, "POST", r.Method) assert.Equal(t, "POST", r.Method)
assert.Equal(t, lfshttp.MediaType, r.Header.Get("Accept")) 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{} body := lockVerifiableRequest{}
if assert.Nil(t, json.NewDecoder(r.Body).Decode(&body)) { if assert.Nil(t, json.NewDecoder(r.Body).Decode(&body)) {