mitchellh / goamz

Golang Amazon Library
Other
672 stars 216 forks source link

s3: no way of adding custom headers when doing a object GET #113

Open client9 opened 10 years ago

client9 commented 10 years ago

Hola,

for S3, one can have custom HTTP headers on a PUT request but not on a GET request.

I would like parity here, but doing the following:

func (b *Bucket) GetResponse(path string) (*http.Response, error) {
    return b.GetResponseHeader(path, make(http.Header))
}
func (b *Bucket) GetResponseHeader(path string, customHeaders http.) (*http.Response, error) {
    req := &request{
        bucket: b.Name,
        path:   path,
                headers: customerHeaders,
    }
        etc
}

Likewise add a GetHeader, and GetReaderHeader

Kinda gross, but not sure of a better way that preserves API compatibility and/or rewrite.

thoughts? I'm happy to do a pull request.

nickg

richardbowden commented 9 years ago

I am interested in this feature, i need to change the content type and content encoding. I have been playing with GetResponseHeader from the original goaws/goaws lib, porting this function to this lib...

got this so far:

s3.go

func (b *Bucket) GetResponseWithHeaders(path string, headers map[string][]string) (data []byte, err error) {
    req := &request{
        bucket:  b.Name,
        path:    path,
        headers: headers,
    }
    fmt.Printf("**** initial headers: %v\n\n\n", req)
    err = b.S3.prepare(req)
    fmt.Printf("**** headers after prep: %v\n\n\n\n", req)
    if err != nil {
        return nil, err
    }
    for attempt := b.S3.AttemptStrategy.Start(); attempt.Next(); {
        resp, err := b.S3.run(req, nil)
        if shouldRetry(err) && attempt.HasNext() {
            continue
        }
        if err != nil {
            return nil, err
        }

        fmt.Printf("**** headers after get: %v\n\n\n", resp.Header)
        data, err = ioutil.ReadAll(resp.Body)
        resp.Body.Close()
        return data, nil
    }
    panic("unreachable")
} 

also added to S3 struct

aws.AttemptStrategy

this works, pulls back the data, how ever the headers do not seem to be sticking, on printing the headers, the last one shows the content type of the actual file being downloaded, not the one set...

still working on this.