Merge pull request #710 from versity/ben/content_type

fix: set default content type to binary/octet-stream
This commit is contained in:
Ben McClelland
2024-08-02 16:36:54 -07:00
committed by GitHub
2 changed files with 25 additions and 7 deletions
+17 -7
View File
@@ -50,7 +50,8 @@ type S3ApiController struct {
}
const (
iso8601Format = "20060102T150405Z"
iso8601Format = "20060102T150405Z"
defaultContentType = "binary/octet-stream"
)
func New(be backend.Backend, iam auth.IAMService, logger s3log.AuditLogger, evs s3event.S3EventSender, mm *metrics.Manager, debug bool, readonly bool) S3ApiController {
@@ -419,10 +420,15 @@ func (c S3ApiController) GetActions(ctx *fiber.Ctx) error {
lastmod = res.LastModified.Format(timefmt)
}
contentType := getstring(res.ContentType)
if contentType == "" {
contentType = defaultContentType
}
utils.SetResponseHeaders(ctx, []utils.CustomHeader{
{
Key: "Content-Type",
Value: getstring(res.ContentType),
Value: contentType,
},
{
Key: "Content-Encoding",
@@ -2693,12 +2699,16 @@ func (c S3ApiController) HeadObject(ctx *fiber.Ctx) error {
Value: getstring(res.ContentEncoding),
})
}
if res.ContentType != nil {
headers = append(headers, utils.CustomHeader{
Key: "Content-Type",
Value: getstring(res.ContentType),
})
contentType := getstring(res.ContentType)
if contentType == "" {
contentType = defaultContentType
}
headers = append(headers, utils.CustomHeader{
Key: "Content-Type",
Value: contentType,
})
utils.SetResponseHeaders(ctx, headers)
return SendResponse(ctx, nil,
+8
View File
@@ -2954,6 +2954,8 @@ func HeadObject_mp_success(s *S3Conf) error {
})
}
const defaultContentType = "binary/octet-stream"
func HeadObject_success(s *S3Conf) error {
testName := "HeadObject_success"
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
@@ -2992,6 +2994,9 @@ func HeadObject_success(s *S3Conf) error {
if contentLength != dataLen {
return fmt.Errorf("expected data length %v, instead got %v", dataLen, contentLength)
}
if *out.ContentType != defaultContentType {
return fmt.Errorf("expected content type %v, instead got %v", defaultContentType, *out.ContentType)
}
return nil
})
@@ -3376,6 +3381,9 @@ func GetObject_success(s *S3Conf) error {
if *out.ContentLength != dataLength {
return fmt.Errorf("expected content-length %v, instead got %v", dataLength, out.ContentLength)
}
if *out.ContentType != defaultContentType {
return fmt.Errorf("expected content type %v, instead got %v", defaultContentType, *out.ContentType)
}
bdy, err := io.ReadAll(out.Body)
if err != nil {