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

Commit 56d51e9

Browse files
committed
add etag header to request object
1 parent f4ff727 commit 56d51e9

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

openstack/objectstorage/v1/objects/requests.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"crypto/sha1"
77
"fmt"
88
"io"
9-
"net/http"
109
"strings"
1110
"time"
1211

@@ -212,26 +211,23 @@ func Create(c *gophercloud.ServiceClient, containerName, objectName string, cont
212211
url += query
213212
}
214213

214+
hash := md5.New()
215+
io.Copy(hash, content)
216+
localChecksum := hash.Sum(nil)
217+
fmt.Printf("localChecksum: %s", fmt.Sprintf("%x", localChecksum))
218+
219+
h["ETag"] = fmt.Sprintf("%x", localChecksum)
220+
215221
ropts := gophercloud.RequestOpts{
216222
RawBody: content,
217223
MoreHeaders: h,
218224
}
219225

220-
doUpload := func() (*http.Response, error) {
226+
for i := 1; i <= 3; i++ {
221227
resp, err := c.Request("PUT", url, ropts)
222228
if resp != nil {
223229
res.Header = resp.Header
224230
}
225-
return resp, err
226-
}
227-
228-
hash := md5.New()
229-
io.Copy(hash, content)
230-
localChecksum := hash.Sum(nil)
231-
fmt.Printf("localChecksum: %s", fmt.Sprintf("%x", localChecksum))
232-
233-
for i := 1; i <= 3; i++ {
234-
resp, err := doUpload()
235231
fmt.Printf("ETag: %s", resp.Header.Get("ETag"))
236232
if resp.Header.Get("ETag") == fmt.Sprintf("%x", localChecksum) {
237233
res.Err = err

0 commit comments

Comments
 (0)