Merge lp:~surma/goamz/put-headers into lp:goamz

Proposed by Alexander Surma
Status: Needs review
Proposed branch: lp:~surma/goamz/put-headers
Merge into: lp:goamz
Diff against target: 43 lines (+14/-8)
1 file modified
s3/s3.go (+14/-8)
To merge this branch: bzr merge lp:~surma/goamz/put-headers
Reviewer Review Type Date Requested Status
goamz maintainers Pending
Review via email: mp+232038@code.launchpad.net

Description of the change

Sorry for taking so long, work has kept me quite busy :)

https://bugs.launchpad.net/goamz/+bug/1321254

To post a comment you must log in.
Revision history for this message
Dimiter Naydenov (dimitern) wrote :

@surma can you re-propose this against http://github.com/go-amz/amz ?

Unmerged revisions

50. By Alexander Surma

s3: Add new PutReaderWithHeader method

      Related to bug report #1321254, a new method was added that supports
      setting arbitrary HTTP headers on PUT to allow things like cache-control.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 's3/s3.go'
2--- s3/s3.go 2014-02-12 13:42:33 +0000
3+++ s3/s3.go 2014-08-25 08:09:26 +0000
4@@ -79,8 +79,8 @@
5 return &Bucket{s3, name}
6 }
7
8-var createBucketConfiguration = `<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
9- <LocationConstraint>%s</LocationConstraint>
10+var createBucketConfiguration = `<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
11+ <LocationConstraint>%s</LocationConstraint>
12 </CreateBucketConfiguration>`
13
14 // locationConstraint returns an io.Reader specifying a LocationConstraint if
15@@ -191,16 +191,22 @@
16 // PutReader inserts an object into the S3 bucket by consuming data
17 // from r until EOF.
18 func (b *Bucket) PutReader(path string, r io.Reader, length int64, contType string, perm ACL) error {
19- headers := map[string][]string{
20- "Content-Length": {strconv.FormatInt(length, 10)},
21- "Content-Type": {contType},
22- "x-amz-acl": {string(perm)},
23- }
24+ return b.PutReaderWithHeader(path, r, length, contType, perm, http.Header{})
25+}
26+
27+// PutReader inserts an object into the S3 bucket by consuming data
28+// from r until EOF. The HTTP PUT request will have the additional
29+// headers provided. This is useful for cache control etc.
30+func (b *Bucket) PutReaderWithHeader(path string, r io.Reader, length int64, contType string, perm ACL, hdrs http.Header) error {
31+ hdrs.Set("Content-Length", strconv.FormatInt(length, 10))
32+ hdrs.Set("Content-Type", contType)
33+ hdrs.Set("x-amz-acl", string(perm))
34+
35 req := &request{
36 method: "PUT",
37 bucket: b.Name,
38 path: path,
39- headers: headers,
40+ headers: hdrs,
41 payload: r,
42 }
43 return b.S3.query(req, nil)

Subscribers

People subscribed via source and target branches