123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- package minio
- import (
- "fmt"
- "net/http"
- "time"
- "github.com/minio/minio-go/v7/pkg/encrypt"
- )
- type AdvancedGetOptions struct {
- ReplicationDeleteMarker bool
- ReplicationProxyRequest string
- }
- type GetObjectOptions struct {
- headers map[string]string
- ServerSideEncryption encrypt.ServerSide
- VersionID string
-
- Internal AdvancedGetOptions
- }
- type StatObjectOptions = GetObjectOptions
- func (o GetObjectOptions) Header() http.Header {
- headers := make(http.Header, len(o.headers))
- for k, v := range o.headers {
- headers.Set(k, v)
- }
- if o.ServerSideEncryption != nil && o.ServerSideEncryption.Type() == encrypt.SSEC {
- o.ServerSideEncryption.Marshal(headers)
- }
-
-
- if o.Internal.ReplicationProxyRequest != "" {
- headers.Set(minIOBucketReplicationProxyRequest, o.Internal.ReplicationProxyRequest)
- }
- return headers
- }
- func (o *GetObjectOptions) Set(key, value string) {
- if o.headers == nil {
- o.headers = make(map[string]string)
- }
- o.headers[http.CanonicalHeaderKey(key)] = value
- }
- func (o *GetObjectOptions) SetMatchETag(etag string) error {
- if etag == "" {
- return errInvalidArgument("ETag cannot be empty.")
- }
- o.Set("If-Match", "\""+etag+"\"")
- return nil
- }
- func (o *GetObjectOptions) SetMatchETagExcept(etag string) error {
- if etag == "" {
- return errInvalidArgument("ETag cannot be empty.")
- }
- o.Set("If-None-Match", "\""+etag+"\"")
- return nil
- }
- func (o *GetObjectOptions) SetUnmodified(modTime time.Time) error {
- if modTime.IsZero() {
- return errInvalidArgument("Modified since cannot be empty.")
- }
- o.Set("If-Unmodified-Since", modTime.Format(http.TimeFormat))
- return nil
- }
- func (o *GetObjectOptions) SetModified(modTime time.Time) error {
- if modTime.IsZero() {
- return errInvalidArgument("Modified since cannot be empty.")
- }
- o.Set("If-Modified-Since", modTime.Format(http.TimeFormat))
- return nil
- }
- func (o *GetObjectOptions) SetRange(start, end int64) error {
- switch {
- case start == 0 && end < 0:
-
- o.Set("Range", fmt.Sprintf("bytes=%d", end))
- case 0 < start && end == 0:
-
-
- o.Set("Range", fmt.Sprintf("bytes=%d-", start))
- case 0 <= start && start <= end:
-
-
- o.Set("Range", fmt.Sprintf("bytes=%d-%d", start, end))
- default:
-
-
-
-
-
-
-
- return errInvalidArgument(
- fmt.Sprintf(
- "Invalid range specified: start=%d end=%d",
- start, end))
- }
- return nil
- }
|