diff --git a/api/handler/get.go b/api/handler/get.go index c524dfc1..881edc13 100644 --- a/api/handler/get.go +++ b/api/handler/get.go @@ -291,17 +291,16 @@ func checkPreconditions(info *data.ObjectInfo, args *conditionalArgs, md5Enabled } func parseConditionalHeaders(headers http.Header) (*conditionalArgs, error) { - var err error args := &conditionalArgs{ IfMatch: data.UnQuote(headers.Get(api.IfMatch)), IfNoneMatch: data.UnQuote(headers.Get(api.IfNoneMatch)), } - if args.IfModifiedSince, err = parseHTTPTime(headers.Get(api.IfModifiedSince)); err != nil { - return nil, err + if httpTime, err := parseHTTPTime(headers.Get(api.IfModifiedSince)); err == nil { + args.IfModifiedSince = httpTime } - if args.IfUnmodifiedSince, err = parseHTTPTime(headers.Get(api.IfUnmodifiedSince)); err != nil { - return nil, err + if httpTime, err := parseHTTPTime(headers.Get(api.IfUnmodifiedSince)); err == nil { + args.IfUnmodifiedSince = httpTime } return args, nil diff --git a/api/handler/head_test.go b/api/handler/head_test.go index 4eebc8c8..b6aec292 100644 --- a/api/handler/head_test.go +++ b/api/handler/head_test.go @@ -68,6 +68,16 @@ func TestConditionalHead(t *testing.T) { api.IfModifiedSince: zeroTime.UTC().Format(http.TimeFormat), } headObject(t, tc, bktName, objName, headers, http.StatusNotModified) + + headers = map[string]string{ + api.IfUnmodifiedSince: zeroTime.UTC().Format(time.RFC3339), // invalid format, header is ignored + } + headObject(t, tc, bktName, objName, headers, http.StatusOK) + + headers = map[string]string{ + api.IfModifiedSince: objInfo.Created.Add(time.Minute).Format(time.RFC3339), // invalid format, header is ignored + } + headObject(t, tc, bktName, objName, headers, http.StatusOK) } func headObject(t *testing.T, tc *handlerContext, bktName, objName string, headers map[string]string, status int) { diff --git a/api/handler/patch.go b/api/handler/patch.go index a9e79bc6..fab7a157 100644 --- a/api/handler/patch.go +++ b/api/handler/patch.go @@ -138,13 +138,12 @@ func (h *handler) PatchObjectHandler(w http.ResponseWriter, r *http.Request) { } func parsePatchConditionalHeaders(headers http.Header) (*conditionalArgs, error) { - var err error args := &conditionalArgs{ IfMatch: data.UnQuote(headers.Get(api.IfMatch)), } - if args.IfUnmodifiedSince, err = parseHTTPTime(headers.Get(api.IfUnmodifiedSince)); err != nil { - return nil, err + if httpTime, err := parseHTTPTime(headers.Get(api.IfUnmodifiedSince)); err == nil { + args.IfUnmodifiedSince = httpTime } return args, nil diff --git a/api/handler/patch_test.go b/api/handler/patch_test.go index aa294230..33aa3393 100644 --- a/api/handler/patch_test.go +++ b/api/handler/patch_test.go @@ -60,6 +60,13 @@ func TestPatch(t *testing.T) { api.IfMatch: etag, }, }, + { + name: "If-Unmodified-Since invalid format, header is ignored", + rng: "bytes 0-2/*", + headers: map[string]string{ + api.IfUnmodifiedSince: created.Add(-24 * time.Hour).Format(time.RFC3339), + }, + }, { name: "invalid range syntax", rng: "bytes 0-2",