Skip to content

Commit

Permalink
fix: support upload object without content type (#7130)
Browse files Browse the repository at this point in the history
default to use "application/octet-stream" content type
  • Loading branch information
nopcoder authored Dec 8, 2023
1 parent 79c5316 commit 17a5305
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2663,7 +2663,7 @@ func (c *Controller) UploadObject(w http.ResponseWriter, r *http.Request, reposi
}

// read request body parse multipart for "content" and upload the data
contentType := r.Header.Get("Content-Type")
contentType := catalog.ContentTypeOrDefault(r.Header.Get("Content-Type"))
mediaType, p, err := mime.ParseMediaType(contentType)
if err != nil {
writeError(w, r, http.StatusInternalServerError, err)
Expand Down
16 changes: 13 additions & 3 deletions pkg/api/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2256,8 +2256,9 @@ func TestController_ObjectsUploadObjectHandler(t *testing.T) {
t.Fatal(err)
}

const content = "hello world this is my awesome content"

t.Run("upload object", func(t *testing.T) {
const content = "hello world this is my awesome content"
resp, err := uploadObjectHelper(t, ctx, clt, "foo/bar", strings.NewReader(content), repo, "main")
verifyResponseOK(t, resp, err)

Expand All @@ -2282,7 +2283,6 @@ func TestController_ObjectsUploadObjectHandler(t *testing.T) {
})

t.Run("upload object missing branch", func(t *testing.T) {
const content = "hello world this is my awesome content"
resp, err := uploadObjectHelper(t, ctx, clt, "foo/bar", strings.NewReader(content), repo, "mainX")
testutil.Must(t, err)
if resp.JSON404 == nil {
Expand All @@ -2291,13 +2291,23 @@ func TestController_ObjectsUploadObjectHandler(t *testing.T) {
})

t.Run("upload object missing repo", func(t *testing.T) {
const content = "hello world this is my awesome content"
resp, err := uploadObjectHelper(t, ctx, clt, "foo/bar", strings.NewReader(content), "repo55555", "main")
testutil.Must(t, err)
if resp.JSON404 == nil {
t.Fatal("Missing repository should return not found")
}
})

t.Run("upload object missing content type", func(t *testing.T) {
const contentType = ""
resp, err := clt.UploadObjectWithBodyWithResponse(ctx, repo, "main", &apigen.UploadObjectParams{
Path: "foo/bar-no-content-type",
}, contentType, strings.NewReader(content))
testutil.Must(t, err)
if resp.JSON201 == nil {
t.Fatal("Missing content type should be successful, got status", resp.Status())
}
})
}

func TestController_ObjectsStageObjectHandler(t *testing.T) {
Expand Down

0 comments on commit 17a5305

Please sign in to comment.