Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 046c882

Browse files
committed
copy reader before making hash
1 parent 56d51e9 commit 046c882

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

openstack/objectstorage/v1/objects/requests.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package objects
22

33
import (
4+
"bytes"
45
"crypto/hmac"
56
"crypto/md5"
67
"crypto/sha1"
@@ -9,9 +10,9 @@ import (
910
"strings"
1011
"time"
1112

12-
"github.com/rackspace/gophercloud"
13-
"github.com/rackspace/gophercloud/openstack/objectstorage/v1/accounts"
14-
"github.com/rackspace/gophercloud/pagination"
13+
"github.com/jrperritt/rack/internal/github.com/rackspace/gophercloud"
14+
"github.com/jrperritt/rack/internal/github.com/rackspace/gophercloud/openstack/objectstorage/v1/accounts"
15+
"github.com/jrperritt/rack/internal/github.com/rackspace/gophercloud/pagination"
1516
)
1617

1718
// ListOptsBuilder allows extensions to add additional parameters to the List
@@ -211,15 +212,18 @@ func Create(c *gophercloud.ServiceClient, containerName, objectName string, cont
211212
url += query
212213
}
213214

215+
var contentBuffer *bytes.Buffer
216+
contentReader := io.TeeReader(content, contentBuffer)
217+
214218
hash := md5.New()
215-
io.Copy(hash, content)
219+
io.Copy(hash, contentReader)
216220
localChecksum := hash.Sum(nil)
217221
fmt.Printf("localChecksum: %s", fmt.Sprintf("%x", localChecksum))
218222

219223
h["ETag"] = fmt.Sprintf("%x", localChecksum)
220224

221225
ropts := gophercloud.RequestOpts{
222-
RawBody: content,
226+
RawBody: strings.NewReader(contentBuffer.String()),
223227
MoreHeaders: h,
224228
}
225229

0 commit comments

Comments
 (0)