Skip to content

Commit

Permalink
private/default: Add support for 1digit RFC822 datetime day in Attemp…
Browse files Browse the repository at this point in the history
…tClockSkewHandler (#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
  • Loading branch information
TrojanXing committed May 7, 2020
1 parent a121095 commit a72ac10
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ SDK Enhancements

SDK Bugs
---
`service/s3`: Fix S3 client behavior wrt 200 OK response with empty payload
* `aws/defaults`: Fix handling of unexpected Date response header value ([#](https://github.com/aws/aws-sdk-go-v2/pull/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](https://github.com/aws/aws-sdk-go-v2/issues/556)
* `service/s3`: Fix S3 client behavior wrt 200 OK response with empty payload
7 changes: 7 additions & 0 deletions aws/defaults/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/awserr"
"github.com/aws/aws-sdk-go-v2/internal/sdk"
"github.com/aws/aws-sdk-go-v2/private/protocol"
)

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

respDate, err := http.ParseTime(respDateHeader)
if err != nil {
// Fallback trying the SDK's RFC 822 datetime format parsing which handles 1digit formatted
// day of month pattern. RFC 2616 states the RFC 822 datetime muse use 2digit days, but some
// APIs may respond with the incorrect format.
respDate, err = protocol.ParseTime(protocol.RFC822TimeFormatName, respDateHeader)
}
if err != nil {
if r.Config.Logger != nil {
r.Config.Logger.Log(fmt.Sprintf("ERROR: unable to determine clock skew for %s/%s API response, invalid Date header value, %v",
Expand Down
12 changes: 12 additions & 0 deletions aws/defaults/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,18 @@ func TestAttemptClockSkewHandler(t *testing.T) {
},
},
},
"RFC822 1digit day time format support": {
Req: &aws.Request{
HTTPResponse: &http.Response{
StatusCode: 200,
Header: http.Header{
"Date": []string{"Thu, 5 Mar 2020 22:25:15 GMT"},
},
},
ResponseAt: time.Date(2020, 3, 5, 22, 25, 17, 0, time.UTC),
},
Expect: []time.Duration{-2 * time.Second},
},
"first date response": {
Req: &aws.Request{
HTTPResponse: &http.Response{
Expand Down

0 comments on commit a72ac10

Please sign in to comment.