Skip to content

Commit

Permalink
Merge pull request #232 from nspcc-dev/231-fix-content-type
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-khimov authored Aug 12, 2024
2 parents 2d1adcf + cdadf18 commit 85b20ee
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 5 additions & 1 deletion handlers/newObjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (a *RestAPI) NewUploadContainerObject(ctx echo.Context, containerID apiserv
// prepares attributes from filtered headers
for key, val := range filtered {
attribute := object.NewAttribute(key, val)
a.log.Debug("Added attribute", zap.String("key", key), zap.String("value", val))
attributes = append(attributes, *attribute)
}

Expand All @@ -76,6 +77,7 @@ func (a *RestAPI) NewUploadContainerObject(ctx echo.Context, containerID apiserv
if _, ok := filtered[object.AttributeContentType]; !ok {
if ct := ctx.Request().Header.Get("Content-Type"); len(ct) > 0 {
attrContentType := object.NewAttribute(object.AttributeContentType, ct)
a.log.Debug("Added attribute", zap.String("key", object.AttributeContentType), zap.String("value", ct))
attributes = append(attributes, *attrContentType)
}
}
Expand All @@ -91,7 +93,9 @@ func (a *RestAPI) NewUploadContainerObject(ctx echo.Context, containerID apiserv
return ctx.JSON(http.StatusBadRequest, resp)
}

timestamp := object.NewAttribute(object.AttributeTimestamp, strconv.FormatInt(parsedTime.Unix(), 10))
tsStr := strconv.FormatInt(parsedTime.Unix(), 10)
timestamp := object.NewAttribute(object.AttributeTimestamp, tsStr)
a.log.Debug("Added attribute", zap.String("key", object.AttributeTimestamp), zap.String("value", tsStr))
attributes = append(attributes, *timestamp)
}
}
Expand Down
6 changes: 2 additions & 4 deletions handlers/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,8 @@ func (a *RestAPI) getByAddress(ctx echo.Context, addr oid.Address, downloadParam
} else {
contentType = http.DetectContentType(nil)
}

ctx.Response().Header().Set("Content-Type", contentType)
}
ctx.Response().Header().Set("Content-Type", contentType)

ctx.Response().Header().Set(accessControlAllowOriginHeader, "*")
return ctx.Stream(http.StatusOK, contentType, payload)
Expand Down Expand Up @@ -541,9 +540,8 @@ func (a *RestAPI) headByAddress(ctx echo.Context, addr oid.Address, downloadPara
} else {
contentType = http.DetectContentType(nil)
}

ctx.Response().Header().Set("Content-Type", contentType)
}
ctx.Response().Header().Set("Content-Type", contentType)

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion handlers/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func filterAttributes(logger *zap.Logger, attributes map[string]string) map[stri
delete(attributes, key)
continue
}
logger.Debug("Added attribute to result object", zap.String("key", key), zap.String("value", value))
logger.Debug("Filtered attribute", zap.String("key", key), zap.String("value", value))
}
return attributes
}
Expand Down

0 comments on commit 85b20ee

Please sign in to comment.