Skip to content

Commit a72ac10

Browse files
authored
private/default: Add support for 1digit RFC822 datetime day in AttemptClockSkewHandler (#560)
Fixes the SDK's behavior to parse unexpected HTTP Date header received that was formated with single digit day of the month instead of two digit RFC822 datetime like defined in RFC 2616. This should prevent log messages about unable to compute clock skew. Fixes #556
1 parent a121095 commit a72ac10

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG_PENDING.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ SDK Enhancements
99

1010
SDK Bugs
1111
---
12-
`service/s3`: Fix S3 client behavior wrt 200 OK response with empty payload
12+
* `aws/defaults`: Fix handling of unexpected Date response header value ([#](https://github.com/aws/aws-sdk-go-v2/pull/560))
13+
* Fixes the SDK's behavior to parse unexpected HTTP Date header received that was formated with single digit day of the month instead of two digit RFC822 datetime like defined in RFC 2616. This should prevent log messages about unable to compute clock skew.
14+
* Fixes [#556](https://github.com/aws/aws-sdk-go-v2/issues/556)
15+
* `service/s3`: Fix S3 client behavior wrt 200 OK response with empty payload

aws/defaults/handlers.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/aws/aws-sdk-go-v2/aws"
1616
"github.com/aws/aws-sdk-go-v2/aws/awserr"
1717
"github.com/aws/aws-sdk-go-v2/internal/sdk"
18+
"github.com/aws/aws-sdk-go-v2/private/protocol"
1819
)
1920

2021
// Interface for matching types which also have a Len method.
@@ -304,6 +305,12 @@ var AttemptClockSkewHandler = aws.NamedHandler{
304305
}
305306

306307
respDate, err := http.ParseTime(respDateHeader)
308+
if err != nil {
309+
// Fallback trying the SDK's RFC 822 datetime format parsing which handles 1digit formatted
310+
// day of month pattern. RFC 2616 states the RFC 822 datetime muse use 2digit days, but some
311+
// APIs may respond with the incorrect format.
312+
respDate, err = protocol.ParseTime(protocol.RFC822TimeFormatName, respDateHeader)
313+
}
307314
if err != nil {
308315
if r.Config.Logger != nil {
309316
r.Config.Logger.Log(fmt.Sprintf("ERROR: unable to determine clock skew for %s/%s API response, invalid Date header value, %v",

aws/defaults/handlers_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,18 @@ func TestAttemptClockSkewHandler(t *testing.T) {
494494
},
495495
},
496496
},
497+
"RFC822 1digit day time format support": {
498+
Req: &aws.Request{
499+
HTTPResponse: &http.Response{
500+
StatusCode: 200,
501+
Header: http.Header{
502+
"Date": []string{"Thu, 5 Mar 2020 22:25:15 GMT"},
503+
},
504+
},
505+
ResponseAt: time.Date(2020, 3, 5, 22, 25, 17, 0, time.UTC),
506+
},
507+
Expect: []time.Duration{-2 * time.Second},
508+
},
497509
"first date response": {
498510
Req: &aws.Request{
499511
HTTPResponse: &http.Response{

0 commit comments

Comments
 (0)