Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Content-Language #1822

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions fakestorage/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type ObjectAttrs struct {
ContentType string
ContentEncoding string
ContentDisposition string
ContentLanguage string
CacheControl string
// Crc32c checksum of Content. calculated by server when it's upload methods are used.
Crc32c string
Expand Down Expand Up @@ -62,6 +63,7 @@ type jsonObject struct {
ContentType string `json:"contentType"`
ContentEncoding string `json:"contentEncoding"`
ContentDisposition string `json:"contentDisposition"`
ContentLanguage string `json:"contentLanguage"`
Crc32c string `json:"crc32c,omitempty"`
Md5Hash string `json:"md5Hash,omitempty"`
Etag string `json:"etag,omitempty"`
Expand All @@ -82,6 +84,7 @@ func (o ObjectAttrs) MarshalJSON() ([]byte, error) {
ContentType: o.ContentType,
ContentEncoding: o.ContentEncoding,
ContentDisposition: o.ContentDisposition,
ContentLanguage: o.ContentLanguage,
Size: o.Size,
Crc32c: o.Crc32c,
Md5Hash: o.Md5Hash,
Expand Down Expand Up @@ -111,6 +114,7 @@ func (o *ObjectAttrs) UnmarshalJSON(data []byte) error {
o.ContentType = temp.ContentType
o.ContentEncoding = temp.ContentEncoding
o.ContentDisposition = temp.ContentDisposition
o.ContentLanguage = temp.ContentLanguage
o.Size = temp.Size
o.Crc32c = temp.Crc32c
o.Md5Hash = temp.Md5Hash
Expand Down Expand Up @@ -397,6 +401,7 @@ func toBackendObjects(objects []StreamingObject) []backend.StreamingObject {
ContentType: o.ContentType,
ContentEncoding: o.ContentEncoding,
ContentDisposition: o.ContentDisposition,
ContentLanguage: o.ContentLanguage,
CacheControl: o.CacheControl,
ACL: o.ACL,
Created: getCurrentIfZero(o.Created).Format(timestampFormat),
Expand All @@ -423,6 +428,7 @@ func bufferedObjectsToBackendObjects(objects []Object) []backend.StreamingObject
ContentType: o.ContentType,
ContentEncoding: o.ContentEncoding,
ContentDisposition: o.ContentDisposition,
ContentLanguage: o.ContentLanguage,
ACL: o.ACL,
Created: getCurrentIfZero(o.Created).Format(timestampFormat),
Deleted: o.Deleted.Format(timestampFormat),
Expand Down Expand Up @@ -452,6 +458,7 @@ func fromBackendObjects(objects []backend.StreamingObject) []StreamingObject {
ContentType: o.ContentType,
ContentEncoding: o.ContentEncoding,
ContentDisposition: o.ContentDisposition,
ContentLanguage: o.ContentLanguage,
CacheControl: o.CacheControl,
Crc32c: o.Crc32c,
Md5Hash: o.Md5Hash,
Expand Down Expand Up @@ -480,6 +487,7 @@ func fromBackendObjectsAttrs(objectAttrs []backend.ObjectAttrs) []ObjectAttrs {
ContentType: o.ContentType,
ContentEncoding: o.ContentEncoding,
ContentDisposition: o.ContentDisposition,
ContentLanguage: o.ContentLanguage,
CacheControl: o.CacheControl,
Crc32c: o.Crc32c,
Md5Hash: o.Md5Hash,
Expand Down Expand Up @@ -783,6 +791,9 @@ func (s *Server) rewriteObject(r *http.Request) jsonResponse {
if metadata.ContentDisposition == "" {
metadata.ContentDisposition = obj.ContentDisposition
}
if metadata.ContentLanguage == "" {
metadata.ContentLanguage = obj.ContentLanguage
}

dstBucket := vars["destinationBucket"]
newObject := StreamingObject{
Expand All @@ -793,6 +804,7 @@ func (s *Server) rewriteObject(r *http.Request) jsonResponse {
ContentType: metadata.ContentType,
ContentEncoding: metadata.ContentEncoding,
ContentDisposition: metadata.ContentDisposition,
ContentLanguage: metadata.ContentLanguage,
Metadata: metadata.Metadata,
},
Content: obj.Content,
Expand Down Expand Up @@ -912,6 +924,9 @@ func (s *Server) downloadObject(w http.ResponseWriter, r *http.Request) {
if obj.ContentDisposition != "" {
w.Header().Set("Content-Disposition", obj.ContentDisposition)
}
if obj.ContentLanguage != "" {
w.Header().Set("Content-Language", obj.ContentLanguage)
}
// X-Goog-Stored-Content-Encoding must be set to the original encoding,
// defaulting to "identity" if no encoding was set.
storedContentEncoding := "identity"
Expand Down Expand Up @@ -1037,6 +1052,7 @@ func (s *Server) patchObject(r *http.Request) jsonResponse {
ContentType string
ContentEncoding string
ContentDisposition string
ContentLanguage string
Metadata map[string]string `json:"metadata"`
CustomTime string
Acl []acls
Expand All @@ -1054,6 +1070,7 @@ func (s *Server) patchObject(r *http.Request) jsonResponse {
attrsToUpdate.ContentType = payload.ContentType
attrsToUpdate.ContentEncoding = payload.ContentEncoding
attrsToUpdate.ContentDisposition = payload.ContentDisposition
attrsToUpdate.ContentLanguage = payload.ContentLanguage
attrsToUpdate.Metadata = payload.Metadata
attrsToUpdate.CustomTime = payload.CustomTime

Expand Down Expand Up @@ -1092,6 +1109,7 @@ func (s *Server) updateObject(r *http.Request) jsonResponse {
Metadata map[string]string `json:"metadata"`
ContentType string `json:"contentType"`
ContentDisposition string `json:"contentDisposition"`
ContentLanguage string `json:"contentLanguage"`
CustomTime string
Acl []acls
}
Expand All @@ -1109,6 +1127,7 @@ func (s *Server) updateObject(r *http.Request) jsonResponse {
attrsToUpdate.CustomTime = payload.CustomTime
attrsToUpdate.ContentType = payload.ContentType
attrsToUpdate.ContentDisposition = payload.ContentDisposition
attrsToUpdate.ContentLanguage = payload.ContentLanguage
if len(payload.Acl) > 0 {
attrsToUpdate.ACL = []storage.ACLRule{}
for _, aclData := range payload.Acl {
Expand Down Expand Up @@ -1142,6 +1161,7 @@ func (s *Server) composeObject(r *http.Request) jsonResponse {
Bucket string
ContentType string
ContentDisposition string
ContentLanguage string
Metadata map[string]string
}
}
Expand Down
5 changes: 5 additions & 0 deletions fakestorage/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func getObjectTestCases() objectTestCases {
contentType = "text/plain; charset=utf-8"
contentEncoding = "gzip"
contentDisposition = "attachment; filename=\"replaced.txt\""
contentLanguage = "fr"
metaValue = "MetaValue"
)
testInitExecTime := time.Now().Truncate(time.Microsecond)
Expand Down Expand Up @@ -113,6 +114,7 @@ func getObjectTestCases() objectTestCases {
ContentType: contentType,
ContentEncoding: contentEncoding,
ContentDisposition: contentDisposition,
ContentLanguage: contentLanguage,
Crc32c: checksum.EncodedChecksum(uint32ToBytes(u32Checksum)),
Md5Hash: checksum.EncodedHash(hash),
Metadata: map[string]string{"MetaHeader": metaValue},
Expand Down Expand Up @@ -175,6 +177,9 @@ func checkObjectAttrs(testObj Object, attrs *storage.ObjectAttrs, t *testing.T)
if attrs.ContentDisposition != testObj.ContentDisposition {
t.Errorf("wrong content disposition\nwant %q\ngot %q", testObj.ContentDisposition, attrs.ContentDisposition)
}
if attrs.ContentLanguage != testObj.ContentLanguage {
t.Errorf("wrong content language\nwant %q\ngot %q", testObj.ContentLanguage, attrs.ContentLanguage)
}
if testObj.Content != nil && attrs.Size != int64(len(testObj.Content)) {
t.Errorf("wrong size returned\nwant %d\ngot %d", len(testObj.Content), attrs.Size)
}
Expand Down
2 changes: 2 additions & 0 deletions fakestorage/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type objectResponse struct {
ContentType string `json:"contentType,omitempty"`
ContentEncoding string `json:"contentEncoding,omitempty"`
ContentDisposition string `json:"contentDisposition,omitempty"`
ContentLanguage string `json:"contentLanguage,omitempty"`
Crc32c string `json:"crc32c,omitempty"`
ACL []*objectAccessControl `json:"acl,omitempty"`
Md5Hash string `json:"md5Hash,omitempty"`
Expand Down Expand Up @@ -156,6 +157,7 @@ func newObjectResponse(obj ObjectAttrs, externalURL string) objectResponse {
ContentType: obj.ContentType,
ContentEncoding: obj.ContentEncoding,
ContentDisposition: obj.ContentDisposition,
ContentLanguage: obj.ContentLanguage,
Crc32c: obj.Crc32c,
Md5Hash: obj.Md5Hash,
Etag: obj.Etag,
Expand Down
2 changes: 2 additions & 0 deletions fakestorage/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type multipartMetadata struct {
ContentType string `json:"contentType"`
ContentEncoding string `json:"contentEncoding"`
ContentDisposition string `json:"contentDisposition"`
ContentLanguage string `json:"ContentLanguage"`
CacheControl string `json:"cacheControl"`
CustomTime time.Time `json:"customTime,omitempty"`
Name string `json:"name"`
Expand Down Expand Up @@ -382,6 +383,7 @@ func (s *Server) multipartUpload(bucketName string, r *http.Request) jsonRespons
CacheControl: metadata.CacheControl,
ContentEncoding: metadata.ContentEncoding,
ContentDisposition: metadata.ContentDisposition,
ContentLanguage: metadata.ContentLanguage,
CustomTime: metadata.CustomTime,
ACL: getObjectACL(predefinedACL),
Metadata: metadata.Metadata,
Expand Down
1 change: 1 addition & 0 deletions internal/backend/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ObjectAttrs struct {
ContentType string
ContentEncoding string
ContentDisposition string
ContentLanguage string
CacheControl string
Crc32c string
Md5Hash string
Expand Down
2 changes: 2 additions & 0 deletions internal/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (g *Server) GetObject(ctx context.Context, req *pb.GetObjectRequest) (*pb.O
Generation: obj.ObjectAttrs.Generation,
ContentType: obj.ObjectAttrs.ContentType,
ContentDisposition: obj.ObjectAttrs.ContentDisposition,
ContentLanguage: obj.ObjectAttrs.ContentLanguage,
}, nil
}

Expand All @@ -136,6 +137,7 @@ func (g *Server) PatchObject(ctx context.Context, req *pb.PatchObjectRequest) (*
ContentType: req.Metadata.ContentType,
ContentEncoding: req.Metadata.ContentEncoding,
ContentDisposition: req.Metadata.ContentDisposition,
ContentLanguage: req.Metadata.ContentLanguage,
}
obj, err := g.backend.PatchObject(req.Bucket, req.Object, attrs)
return makeObject(obj), err
Expand Down