Skip to content

Commit d2de41c

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

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

swift.go

Lines changed: 12 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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)