Merge pull request #14 from digitalocean/wwarren/set-ContentLength-on-HeadObjectOutput

s3: work around buggy s3 api client implementation
This commit is contained in:
wayne 2020-11-04 15:33:55 -06:00 committed by GitHub
commit e465862185
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -585,6 +585,28 @@ func (d *driver) logS3Operation(ctx context.Context) request.NamedHandler {
}
}
// setContentLengthHandlerHame is used to identify the handler used set the
// ContentLength field on request data output types that support it.
const setContentLengthHandlerName = "docker.storage-driver.s3.set-content-length"
// setContentLength is used to set the ContentLength field on request data
// output types that support it.
var setContentLength = request.NamedHandler{
Name: setContentLengthHandlerName,
Fn: func(r *request.Request) {
switch v := r.Data.(type) {
case *s3.HeadObjectOutput:
if r.HTTPResponse.ContentLength > 0 {
v.SetContentLength(r.HTTPResponse.ContentLength)
}
case *s3.GetObjectOutput:
if r.HTTPResponse.ContentLength > 0 {
v.SetContentLength(r.HTTPResponse.ContentLength)
}
}
},
}
func (d *driver) s3Client(ctx context.Context) *s3.S3 {
s := d.S3
@ -593,6 +615,7 @@ func (d *driver) s3Client(ctx context.Context) *s3.S3 {
r := d.logS3Operation(ctx)
s.Client.Handlers.Complete.PushBackNamed(r)
}
s.Client.Handlers.Complete.PushBackNamed(setContentLength)
return s
}
@ -714,7 +737,7 @@ func (d *driver) Stat(ctx context.Context, path string) (storagedriver.FileInfo,
Bucket: aws.String(d.Bucket),
Key: aws.String(d.s3Path(path)),
})
if err == nil {
if err == nil && headResp.ContentLength != nil {
if headResp.ContentLength != nil {
fi.Size = *headResp.ContentLength
}