From c4631e5806b18b86879c632caa67cb878b036809 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Thu, 1 Jul 2021 14:24:00 +0300 Subject: [PATCH] [#94] Refactoring Signed-off-by: Denis Kirillov --- api/handler/copy.go | 8 ++++---- api/handler/get.go | 22 ++++++++++------------ 2 files changed, 14 insertions(+), 16 deletions(-) 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) {