Skip to content

Commit

Permalink
Fix S3 HeadObject endpoint not correctly checking 404 (#1091)
Browse files Browse the repository at this point in the history
A result of moving to a HEAD request which doesn't have a body and
requires checking the status code.
  • Loading branch information
ChrisSchinnerl committed Mar 25, 2024
2 parents 14ddedb + 1cb3ac1 commit 9fe12d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions internal/test/e2e/s3_test.go
Expand Up @@ -113,6 +113,12 @@ func TestS3Basic(t *testing.T) {
t.Fatal("unexpected ETag:", info.ETag)
}

// stat object that doesn't exist
_, err = s3.StatObject(context.Background(), bucket, "nonexistent", minio.StatObjectOptions{})
if err == nil || !strings.Contains(err.Error(), "The specified key does not exist") {
t.Fatal(err)
}

// add another bucket
tt.OK(s3.MakeBucket(context.Background(), bucket+"2", minio.MakeBucketOptions{}))

Expand Down
8 changes: 6 additions & 2 deletions worker/client/client.go
Expand Up @@ -100,9 +100,13 @@ func (c *Client) HeadObject(ctx context.Context, bucket, path string, opts api.H
return nil, err
}
if resp.StatusCode != 200 && resp.StatusCode != 206 {
err, _ := io.ReadAll(resp.Body)
_ = resp.Body.Close()
return nil, errors.New(string(err))
switch resp.StatusCode {
case http.StatusNotFound:
return nil, api.ErrObjectNotFound
default:
return nil, errors.New(http.StatusText(resp.StatusCode))
}
}

head, err := parseObjectResponseHeaders(resp.Header)
Expand Down

0 comments on commit 9fe12d9

Please sign in to comment.