mirror of
https://github.com/distribution/distribution.git
synced 2025-08-27 02:49:29 +00:00
Merge pull request #14 from digitalocean/wwarren/set-ContentLength-on-HeadObjectOutput
s3: work around buggy s3 api client implementation
This commit is contained in:
commit
e465862185
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user