mirror of
https://github.com/versity/versitygw.git
synced 2026-09-04 07:06:59 +00:00
Merge pull request #710 from versity/ben/content_type
fix: set default content type to binary/octet-stream
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user