Skip to content

Commit

Permalink
fix: Fixed the mechanism to put/get object content-type, content-enco…
Browse files Browse the repository at this point in the history
…ding in azure
  • Loading branch information
0x180 committed Sep 11, 2024
1 parent 5b6f806 commit 47d1a79
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
19 changes: 12 additions & 7 deletions backend/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ const (
onameAttr key = "Objname"
onameAttrLower key = "objname"
metaTmpMultipartPrefix key = ".sgwtmp" + "/multipart"

defaultContentType = "binary/octet-stream"
)

func (key) Table() map[string]struct{} {
Expand Down Expand Up @@ -301,10 +299,15 @@ func (az *Azure) PutObject(ctx context.Context, po *s3.PutObjectInput) (string,
opts.HTTPHeaders.BlobContentEncoding = po.ContentEncoding
opts.HTTPHeaders.BlobContentLanguage = po.ContentLanguage
opts.HTTPHeaders.BlobContentDisposition = po.ContentDisposition
opts.HTTPHeaders.BlobContentType = po.ContentType
if strings.HasSuffix(*po.Key, "/") {
// Hardcode "application/x-directory" for direcoty objects
opts.HTTPHeaders.BlobContentType = backend.GetStringPtr(backend.DirContentType)
} else {
opts.HTTPHeaders.BlobContentType = po.ContentType
}

if opts.HTTPHeaders.BlobContentType == nil {
opts.HTTPHeaders.BlobContentType = backend.GetStringPtr(string(defaultContentType))
opts.HTTPHeaders.BlobContentType = backend.GetStringPtr(backend.DefaultContentType)
}

uploadResp, err := az.client.UploadStream(ctx, *po.Bucket, *po.Key, po.Body, opts)
Expand Down Expand Up @@ -401,7 +404,7 @@ func (az *Azure) GetObject(ctx context.Context, input *s3.GetObjectInput) (*s3.G

contentType := blobDownloadResponse.ContentType
if contentType == nil {
contentType = backend.GetStringPtr(defaultContentType)
contentType = backend.GetStringPtr(backend.DefaultContentType)
}

return &s3.GetObjectOutput{
Expand Down Expand Up @@ -855,7 +858,8 @@ func (az *Azure) CreateMultipartUpload(ctx context.Context, input *s3.CreateMult
}
if getString(input.ContentType) != "" {
opts.HTTPHeaders = &blob.HTTPHeaders{
BlobContentType: input.ContentType,
BlobContentType: input.ContentType,
BlobContentEncoding: input.ContentEncoding,
}
}

Expand Down Expand Up @@ -1190,7 +1194,8 @@ func (az *Azure) CompleteMultipartUpload(ctx context.Context, input *s3.Complete
Tags: parseAzTags(tags.BlobTagSet),
}
opts.HTTPHeaders = &blob.HTTPHeaders{
BlobContentType: props.ContentType,
BlobContentType: props.ContentType,
BlobContentEncoding: props.ContentEncoding,
}

resp, err := client.CommitBlockList(ctx, blockIds, opts)
Expand Down
6 changes: 6 additions & 0 deletions backend/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ import (
"github.com/versity/versitygw/s3response"
)

const (
// this is the media type for directories in AWS and Nextcloud
DirContentType = "application/x-directory"
DefaultContentType = "binary/octet-stream"
)

func IsValidBucketName(name string) bool { return true }

type ByBucketName []s3response.ListAllMyBucketsEntry
Expand Down
7 changes: 2 additions & 5 deletions backend/posix/posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ const (
objectRetentionKey = "object-retention"
objectLegalHoldKey = "object-legal-hold"

// this is the media type for directories in AWS and Nextcloud
dirContentType = "application/x-directory"

doFalloc = true
skipFalloc = false
)
Expand Down Expand Up @@ -1739,7 +1736,7 @@ func (p *Posix) GetObject(_ context.Context, input *s3.GetObjectInput) (*s3.GetO
userMetaData := make(map[string]string)

_, contentEncoding := p.loadUserMetaData(bucket, object, userMetaData)
contentType := dirContentType
contentType := backend.DirContentType

b, err := p.meta.RetrieveAttribute(bucket, object, etagkey)
etag := string(b)
Expand Down Expand Up @@ -1898,7 +1895,7 @@ func (p *Posix) HeadObject(ctx context.Context, input *s3.HeadObjectInput) (*s3.
contentType, contentEncoding := p.loadUserMetaData(bucket, object, userMetaData)

if fi.IsDir() {
contentType = dirContentType
contentType = backend.DirContentType
}

b, err := p.meta.RetrieveAttribute(bucket, object, etagkey)
Expand Down
1 change: 0 additions & 1 deletion tests/integration/group-tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ func TestHeadObject(s *S3Conf) {
HeadObject_non_existing_mp(s)
HeadObject_mp_success(s)
HeadObject_non_existing_dir_object(s)
HeadObject_name_too_long(s)
HeadObject_with_contenttype(s)
HeadObject_success(s)
}
Expand Down

0 comments on commit 47d1a79

Please sign in to comment.