Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support upload object without content type #7130

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading