allow non-standards fallback for all http.TimeFormats (#15662)

fixes #15645
This commit is contained in:
Harshavardhana
2022-09-07 07:24:54 -07:00
committed by GitHub
parent 52861d3aea
commit 228c6686f8
8 changed files with 153 additions and 52 deletions
+7 -24
View File
@@ -27,10 +27,11 @@ import (
"sync/atomic"
"time"
"github.com/dustin/go-humanize"
"github.com/minio/minio-go/v7/pkg/set"
xnet "github.com/minio/pkg/net"
"github.com/dustin/go-humanize"
"github.com/minio/minio/internal/amztime"
"github.com/minio/minio/internal/config/dns"
"github.com/minio/minio/internal/crypto"
xhttp "github.com/minio/minio/internal/http"
@@ -241,17 +242,6 @@ func isAdminReq(r *http.Request) bool {
return strings.HasPrefix(r.URL.Path, adminPathPrefix)
}
// Supported amz date formats.
var amzDateFormats = []string{
// Do not change this order, x-amz-date format is usually in
// iso8601Format rest are meant for relaxed handling of other
// odd SDKs that might be out there.
iso8601Format,
time.RFC1123,
time.RFC1123Z,
// Add new AMZ date formats here.
}
// Supported Amz date headers.
var amzDateHeaders = []string{
// Do not chane this order, x-amz-date value should be
@@ -260,24 +250,17 @@ var amzDateHeaders = []string{
"date",
}
// parseAmzDate - parses date string into supported amz date formats.
func parseAmzDate(amzDateStr string) (amzDate time.Time, apiErr APIErrorCode) {
for _, dateFormat := range amzDateFormats {
amzDate, err := time.Parse(dateFormat, amzDateStr)
if err == nil {
return amzDate, ErrNone
}
}
return time.Time{}, ErrMalformedDate
}
// parseAmzDateHeader - parses supported amz date headers, in
// supported amz date formats.
func parseAmzDateHeader(req *http.Request) (time.Time, APIErrorCode) {
for _, amzDateHeader := range amzDateHeaders {
amzDateStr := req.Header.Get(amzDateHeader)
if amzDateStr != "" {
return parseAmzDate(amzDateStr)
t, err := amztime.Parse(amzDateStr)
if err != nil {
return time.Time{}, ErrMalformedDate
}
return t, ErrNone
}
}
// Date header missing.