-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api, core: Introduce a new Core API with GetObject pre-conditions.
Implements a new API to provide a way to set pre-conditions for GetObject() request such as to - read partial data starting at offsets. - read only if etag matches. - read only if modtime matches. - read only if etag doesn't match. - read only if modtime doesn't match. Fixes #669
- Loading branch information
1 parent
550c8c2
commit b82a6f5
Showing
5 changed files
with
130 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Minio Go Library for Amazon S3 Compatible Cloud Storage (C) 2016 Minio, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package minio | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
// GetConditions - get conditions implement methods for setting | ||
// conditions for a GetObject request. | ||
// http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html | ||
type GetConditions struct { | ||
http.Header | ||
} | ||
|
||
// SetMatchETag - set match etag. | ||
func (c GetConditions) SetMatchETag(etag string) error { | ||
if etag == "" { | ||
return ErrInvalidArgument("ETag cannot be empty.") | ||
} | ||
c.Set("If-Match", etag) | ||
return nil | ||
} | ||
|
||
// SetMatchETagExcept - set match etag except. | ||
func (c GetConditions) SetMatchETagExcept(etag string) error { | ||
if etag == "" { | ||
return ErrInvalidArgument("ETag cannot be empty.") | ||
} | ||
c.Set("If-None-Match", etag) | ||
return nil | ||
} | ||
|
||
// SetUnmodified - set unmodified time since. | ||
func (c GetConditions) SetUnmodified(modTime time.Time) error { | ||
if modTime.IsZero() { | ||
return ErrInvalidArgument("Modified since cannot be empty.") | ||
} | ||
c.Set("If-Unmodified-Since", modTime.Format(http.TimeFormat)) | ||
return nil | ||
} | ||
|
||
// SetModified - set modified time since. | ||
func (c GetConditions) SetModified(modTime time.Time) error { | ||
if modTime.IsZero() { | ||
return ErrInvalidArgument("Modified since cannot be empty.") | ||
} | ||
c.Set("If-Modified-Since", modTime.Format(http.TimeFormat)) | ||
return nil | ||
} | ||
|
||
// SetRange - set the start and end offset of the object to be read. | ||
// See https://tools.ietf.org/html/rfc7233#section-3.1 for reference. | ||
func (c GetConditions) SetRange(start, end int64) error { | ||
if start < 0 || end > 0 && end < start { | ||
return ErrInvalidArgument("Range start less than 0 or range end less than range start.") | ||
} | ||
if end == 0 { | ||
// Read everything starting from offset 'start'. | ||
c.Set("Range", fmt.Sprintf("bytes=%d-", start)) | ||
} else { | ||
// Read everything starting at 'start' till the 'end'. | ||
c.Set("Range", fmt.Sprintf("bytes=%d-%d", start, end)) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package minio | ||
|
||
/* | ||
* Minio Go Library for Amazon S3 Compatible Cloud Storage (C) 2017 Minio, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters