From 3c44af8d4e70d84efb63aa77ff8db59a30922f31 Mon Sep 17 00:00:00 2001 From: DarthSim Date: Thu, 17 Mar 2022 20:43:25 +0600 Subject: [PATCH] Fix and improve S3 transport --- CHANGELOG.md | 1 + transport/s3/s3.go | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d488a172..e5373d96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased] ### Fix +- Fix `s3` scheme status codes. - (pro) Fix saving animations to MP4. ## [3.3.2] - 2022-03-17 diff --git a/transport/s3/s3.go b/transport/s3/s3.go index 2870a29f..05f4bce4 100644 --- a/transport/s3/s3.go +++ b/transport/s3/s3.go @@ -2,7 +2,9 @@ package s3 import ( "fmt" + "io" http "net/http" + "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" @@ -60,8 +62,21 @@ func (t transport) RoundTrip(req *http.Request) (resp *http.Response, err error) s3req, _ := t.svc.GetObjectRequest(input) if err := s3req.Send(); err != nil { - if s3err, ok := err.(awserr.RequestFailure); !ok || s3err.StatusCode() != http.StatusNotModified { + if s3err, ok := err.(awserr.RequestFailure); !ok || s3err.StatusCode() < 100 || s3err.StatusCode() == 301 { return nil, err + } else { + body := strings.NewReader(s3err.Message()) + return &http.Response{ + StatusCode: s3err.StatusCode(), + Proto: "HTTP/1.0", + ProtoMajor: 1, + ProtoMinor: 0, + Header: http.Header{}, + ContentLength: int64(body.Len()), + Body: io.NopCloser(body), + Close: false, + Request: s3req.HTTPRequest, + }, nil } }