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
=== modified file 's3/s3.go'
--- s3/s3.go 2014-02-12 13:42:33 +0000
+++ s3/s3.go 2014-08-25 08:09:26 +0000
@@ -79,8 +79,8 @@
79 return &Bucket{s3, name}79 return &Bucket{s3, name}
80}80}
8181
82var createBucketConfiguration = `<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> 82var createBucketConfiguration = `<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
83 <LocationConstraint>%s</LocationConstraint> 83 <LocationConstraint>%s</LocationConstraint>
84</CreateBucketConfiguration>`84</CreateBucketConfiguration>`
8585
86// locationConstraint returns an io.Reader specifying a LocationConstraint if86// locationConstraint returns an io.Reader specifying a LocationConstraint if
@@ -191,16 +191,22 @@
191// PutReader inserts an object into the S3 bucket by consuming data191// PutReader inserts an object into the S3 bucket by consuming data
192// from r until EOF.192// from r until EOF.
193func (b *Bucket) PutReader(path string, r io.Reader, length int64, contType string, perm ACL) error {193func (b *Bucket) PutReader(path string, r io.Reader, length int64, contType string, perm ACL) error {
194 headers := map[string][]string{194 return b.PutReaderWithHeader(path, r, length, contType, perm, http.Header{})
195 "Content-Length": {strconv.FormatInt(length, 10)},195}
196 "Content-Type": {contType},196
197 "x-amz-acl": {string(perm)},197// PutReader inserts an object into the S3 bucket by consuming data
198 }198// from r until EOF. The HTTP PUT request will have the additional
199// headers provided. This is useful for cache control etc.
200func (b *Bucket) PutReaderWithHeader(path string, r io.Reader, length int64, contType string, perm ACL, hdrs http.Header) error {
201 hdrs.Set("Content-Length", strconv.FormatInt(length, 10))
202 hdrs.Set("Content-Type", contType)
203 hdrs.Set("x-amz-acl", string(perm))
204
199 req := &request{205 req := &request{
200 method: "PUT",206 method: "PUT",
201 bucket: b.Name,207 bucket: b.Name,
202 path: path,208 path: path,
203 headers: headers,209 headers: hdrs,
204 payload: r,210 payload: r,
205 }211 }
206 return b.S3.query(req, nil)212 return b.S3.query(req, nil)

Subscribers

People subscribed via source and target branches