Skip to content

Commit

Permalink
support If-Match/If-None-Match for PUT operations (#1772)
Browse files Browse the repository at this point in the history
This is a MinIO specific extension
  • Loading branch information
harshavardhana authored Feb 17, 2023
1 parent a0211ff commit 11047f8
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions api-put-object.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,28 @@ type PutObjectOptions struct {
// This can be used for faster uploads on non-seekable or slow-to-seek input.
ConcurrentStreamParts bool
Internal AdvancedPutOptions

customHeaders http.Header
}

// SetMatchETag if etag matches while PUT MinIO returns an error
// this is a MinIO specific extension to support optimistic locking
// semantics.
func (opts *PutObjectOptions) SetMatchETag(etag string) {
if opts.customHeaders == nil {
opts.customHeaders = http.Header{}
}
opts.customHeaders.Set("If-Match", "\""+etag+"\"")
}

// SetMatchETagExcept if etag does not match while PUT MinIO returns an
// error this is a MinIO specific extension to support optimistic locking
// semantics.
func (opts *PutObjectOptions) SetMatchETagExcept(etag string) {
if opts.customHeaders == nil {
opts.customHeaders = http.Header{}
}
opts.customHeaders.Set("If-None-Match", "\""+etag+"\"")
}

// getNumThreads - gets the number of threads to be used in the multipart
Expand Down Expand Up @@ -187,6 +209,12 @@ func (opts PutObjectOptions) Header() (header http.Header) {
header.Set("x-amz-meta-"+k, v)
}
}

// set any other additional custom headers.
for k, v := range opts.customHeaders {
header[k] = v
}

return
}

Expand Down

0 comments on commit 11047f8

Please sign in to comment.