diff --git a/api/handler/copy.go b/api/handler/copy.go index aa6009d9d..67d5ebb5f 100644 --- a/api/handler/copy.go +++ b/api/handler/copy.go @@ -13,8 +13,8 @@ import ( ) type copyObjectArgs struct { - IfModifiedSince time.Time - IfUnmodifiedSince time.Time + IfModifiedSince *time.Time + IfUnmodifiedSince *time.Time } // path2BucketObject returns bucket and object. @@ -74,11 +74,11 @@ func (h *handler) CopyObjectHandler(w http.ResponseWriter, r *http.Request) { return } - if !args.IfModifiedSince.IsZero() && inf.Created.Before(args.IfModifiedSince) { + if args.IfModifiedSince != nil && inf.Created.Before(*args.IfModifiedSince) { w.WriteHeader(http.StatusNotModified) return } - if !args.IfUnmodifiedSince.IsZero() && inf.Created.After(args.IfUnmodifiedSince) { + if args.IfUnmodifiedSince != nil && inf.Created.After(*args.IfUnmodifiedSince) { w.WriteHeader(http.StatusPreconditionFailed) return } diff --git a/api/handler/get.go b/api/handler/get.go index c431d09e7..eabacd186 100644 --- a/api/handler/get.go +++ b/api/handler/get.go @@ -14,8 +14,8 @@ import ( ) type getObjectArgs struct { - IfModifiedSince time.Time - IfUnmodifiedSince time.Time + IfModifiedSince *time.Time + IfUnmodifiedSince *time.Time } func fetchRangeHeader(headers http.Header, fullSize uint64) (*layer.RangeParams, error) { @@ -90,11 +90,11 @@ func (h *handler) GetObjectHandler(w http.ResponseWriter, r *http.Request) { return } - if !args.IfModifiedSince.IsZero() && inf.Created.Before(args.IfModifiedSince) { + if args.IfModifiedSince != nil && inf.Created.Before(*args.IfModifiedSince) { w.WriteHeader(http.StatusNotModified) return } - if !args.IfUnmodifiedSince.IsZero() && inf.Created.After(args.IfUnmodifiedSince) { + if args.IfUnmodifiedSince != nil && inf.Created.After(*args.IfUnmodifiedSince) { w.WriteHeader(http.StatusPreconditionFailed) return } @@ -133,18 +133,16 @@ func parseGetObjectArgs(headers http.Header) (*getObjectArgs, error) { return args, nil } -func parseHTTPTime(data string) (time.Time, error) { - var result time.Time - var err error - +func parseHTTPTime(data string) (*time.Time, error) { if len(data) == 0 { - return result, nil + return nil, nil } - if result, err = time.Parse(http.TimeFormat, data); err != nil { - return result, fmt.Errorf("couldn't parse http time %s: %w", data, err) + result, err := time.Parse(http.TimeFormat, data) + if err != nil { + return nil, fmt.Errorf("couldn't parse http time %s: %w", data, err) } - return result, nil + return &result, nil } func writeRangeHeaders(w http.ResponseWriter, params *layer.RangeParams, size int64) {