Skip to content

Commit 11047f8

Browse files
support If-Match/If-None-Match for PUT operations (#1772)
This is a MinIO specific extension
1 parent a0211ff commit 11047f8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

api-put-object.go

+28
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,28 @@ type PutObjectOptions struct {
9393
// This can be used for faster uploads on non-seekable or slow-to-seek input.
9494
ConcurrentStreamParts bool
9595
Internal AdvancedPutOptions
96+
97+
customHeaders http.Header
98+
}
99+
100+
// SetMatchETag if etag matches while PUT MinIO returns an error
101+
// this is a MinIO specific extension to support optimistic locking
102+
// semantics.
103+
func (opts *PutObjectOptions) SetMatchETag(etag string) {
104+
if opts.customHeaders == nil {
105+
opts.customHeaders = http.Header{}
106+
}
107+
opts.customHeaders.Set("If-Match", "\""+etag+"\"")
108+
}
109+
110+
// SetMatchETagExcept if etag does not match while PUT MinIO returns an
111+
// error this is a MinIO specific extension to support optimistic locking
112+
// semantics.
113+
func (opts *PutObjectOptions) SetMatchETagExcept(etag string) {
114+
if opts.customHeaders == nil {
115+
opts.customHeaders = http.Header{}
116+
}
117+
opts.customHeaders.Set("If-None-Match", "\""+etag+"\"")
96118
}
97119

98120
// getNumThreads - gets the number of threads to be used in the multipart
@@ -187,6 +209,12 @@ func (opts PutObjectOptions) Header() (header http.Header) {
187209
header.Set("x-amz-meta-"+k, v)
188210
}
189211
}
212+
213+
// set any other additional custom headers.
214+
for k, v := range opts.customHeaders {
215+
header[k] = v
216+
}
217+
190218
return
191219
}
192220

0 commit comments

Comments
 (0)