Skip to content

Commit

Permalink
e2e: fix TestS3List
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Mar 13, 2024
1 parent e27b6f8 commit 5a4cc47
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
9 changes: 6 additions & 3 deletions api/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ func (opts DeleteObjectOptions) Apply(values url.Values) {
}
}

func (opts HeadObjectOptions) Apply(values url.Values) {
if opts.IgnoreDelim {
values.Set("ignoreDelim", "true")
}
}

func (opts HeadObjectOptions) ApplyHeaders(h http.Header) {
if opts.Range != (DownloadRange{}) {
if opts.Range.Length == -1 {
Expand All @@ -320,9 +326,6 @@ func (opts HeadObjectOptions) ApplyHeaders(h http.Header) {
h.Set("Range", fmt.Sprintf("bytes=%v-%v", opts.Range.Offset, opts.Range.Offset+opts.Range.Length-1))
}
}
if opts.IgnoreDelim {
h.Set("ignoreDelim", "true")
}
}

func (opts GetObjectOptions) Apply(values url.Values) {
Expand Down
5 changes: 1 addition & 4 deletions worker/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,9 @@ func (c *Client) DownloadStats() (resp api.DownloadStatsResponse, err error) {
func (c *Client) HeadObject(ctx context.Context, bucket, path string, opts api.HeadObjectOptions) (*api.HeadObjectResponse, error) {
c.c.Custom("HEAD", fmt.Sprintf("/objects/%s", path), nil, nil)

if strings.HasSuffix(path, "/") {
return nil, errors.New("the given path is a directory, HEAD can only be performed on objects")
}

values := url.Values{}
values.Set("bucket", url.QueryEscape(bucket))
opts.Apply(values)
path = api.ObjectPathEscape(path)
path += "?" + values.Encode()

Expand Down
7 changes: 6 additions & 1 deletion worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,16 +860,21 @@ func (w *worker) objectsHandlerHEAD(jc jape.Context) {
if jc.DecodeForm("bucket", &bucket) != nil {
return
}
var ignoreDelim bool
if jc.DecodeForm("ignoreDelim", &ignoreDelim) != nil {
return
}

// parse path
path := jc.PathParam("path")
if path == "" || strings.HasSuffix(path, "/") {
if !ignoreDelim && (path == "" || strings.HasSuffix(path, "/")) {
jc.Error(errors.New("HEAD requests can only be performed on objects, not directories"), http.StatusBadRequest)
return
}

// fetch object metadata
res, err := w.bus.Object(jc.Request.Context(), bucket, path, api.GetObjectOptions{
IgnoreDelim: ignoreDelim,
OnlyMetadata: true,
})
if err != nil && strings.Contains(err.Error(), api.ErrObjectNotFound.Error()) {
Expand Down

0 comments on commit 5a4cc47

Please sign in to comment.