Skip to content

Commit 7bca2dc

Browse files
committed
On Auth failures, rewind the body if possible
This fixes integration test failures for go1.21 and go1.22 which weren't present in go1.20 and previous. Something changed in the go runtime to cause this but the exact cause is unknown.
1 parent 1dc4ed4 commit 7bca2dc

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

swift.go

+12
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,18 @@ func (c *Connection) Call(ctx context.Context, targetUrl string, p RequestOpts)
787787
drainAndClose(resp.Body, nil)
788788
c.UnAuthenticate()
789789
retries--
790+
err = AuthorizationFailed
791+
792+
// Attempt to rewind the body
793+
if p.Body != nil {
794+
if do, ok := p.Body.(io.Seeker); ok {
795+
if _, seekErr := do.Seek(0, io.SeekStart); seekErr != nil {
796+
return
797+
}
798+
} else {
799+
return
800+
}
801+
}
790802
} else {
791803
break
792804
}

swift_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ func TestObjectPutWithReauth(t *testing.T) {
873873
c.AuthToken = "expiredtoken"
874874

875875
r := strings.NewReader(CONTENTS)
876-
_, err := c.ObjectPut(ctx, CONTAINER, OBJECT, r, true, "", "text/plain", nil)
876+
_, err := c.ObjectPut(ctx, CONTAINER, OBJECT, r, false, "", "text/plain", nil)
877877
if err != nil {
878878
t.Fatal(err)
879879
}

0 commit comments

Comments
 (0)