Skip to content

Commit

Permalink
Fix #738 allow copy_object to set content-type (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
vlcinsky authored and kannappanr committed Mar 13, 2019
1 parent ee50fdd commit 897e014
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 21 deletions.
1 change: 1 addition & 0 deletions minio/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ def is_supported_header(key):
supported_headers = [
"cache-control",
"content-encoding",
"content-type",
"content-disposition",
"content-language",
"x-amz-website-redirect-location",
Expand Down
118 changes: 97 additions & 21 deletions tests/unit/header_value_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,100 @@
from minio.helpers import is_storageclass_header,is_amz_header,is_supported_header,amzprefix_user_metadata

class HeaderTests(TestCase):
header_variants = {
"content-type": [
"content-type",
"Content-Type",
"CONTENT-TYPE",
"cONTENT-tYPE",
"cOntent-TypE",
"CoNTENT-tYPe",
],
"x-amz-meta-me": [
"x-amz-meta-me",
"X-Amz-Meta-Me",
"X-AMZ-META-ME",
"x-aMZ-mETA-mE",
],
"cache-control": [
"cache-control" ,
"Cache-Control" ,
"CACHE-CONTROL" ,
"cACHE-cONTROL" ,
"CacHe-conTrol" ,
],
"content-disposition": [
"content-disposition",
"Content-Disposition",
"CONTENT-DISPOSITION",
"cONTENT-dISPOSITION",
"conTent-disPositioN",
],
"content-language": [
"content-language",
"Content-Language",
"CONTENT-LANGUAGE",
"conTent-Language",
],
"x-amz-website-redirect-location": [
"x-amz-website-redirect-location",
"X-Amz-Website-Redirect-Location",
"X-AMZ-WEBSITE-REDIRECT-LOCATION",
"x-aMZ-wEBSITE-rEDIRECT-lOCATION",
],
"x-amz-meta-status-code": [
"x-amz-meta-status-code",
"X-Amz-Meta-Status-Code",
"X-AMZ-META-STATUS-CODE",
"x-aMZ-mETA-sTATUS-cODE",
],
"x-amz-server-side-encryption": [
"x-amz-server-side-encryption",
"X-Amz-Server-Side-Encryption",
"X-AMZ-SERVER-SIDE-ENCRYPTION",
"x-aMZ-sERVER-sIDE-eNCRYPTION",
],
"x-amz-storage-class": [
"x-amz-storage-class",
"X-Amz-Storage-Class",
"X-AMZ-STORAGE-CLASS",
"x-aMZ-sTORAGE-cLASS",
],
}

def check_ok_header(self, check_fun, header):
for header_variant in self.header_variants.get(header, [header]):
eq_(check_fun(header_variant), True)

def check_bad_header(self, check_fun, header):
for header_variant in self.header_variants.get(header, [header]):
eq_(check_fun(header_variant), False)

def test_is_supported_header(self):
eq_(is_supported_header("content-type"),False)
eq_(is_supported_header("Content-Type"),False)
eq_(is_supported_header("cOntent-TypE"),False)
eq_(is_supported_header("x-amz-meta-me"),False)
eq_(is_supported_header("Cache-Control"),True)
eq_(is_supported_header("content-encoding"),True)
eq_(is_supported_header("content-disposition"),True)
eq_(is_supported_header("content-language"),True)
eq_(is_supported_header("x-amz-website-redirect-location"),True)
self.check_ok_header(is_supported_header, "content-type")
self.check_ok_header(is_supported_header, "cache-control")
self.check_ok_header(is_supported_header, "content-disposition")
self.check_ok_header(is_supported_header, "content-encoding")
self.check_ok_header(is_supported_header, "content-language")
self.check_ok_header(is_supported_header, "x-amz-website-redirect-location")

def test_is_not_supported_header(self):
self.check_bad_header(is_supported_header, "x-amz-meta-me")

def test_is_amz_header(self):
eq_(is_amz_header("x-amz-meta-status-code"),True)
eq_(is_amz_header("X-Amz-Meta-status-code"),True)
eq_(is_amz_header("X_AMZ_META-VALUE"),False)
eq_(is_amz_header("content-type"),False)
eq_(is_amz_header("x-amz-server-side-encryption"),True)
self.check_ok_header(is_amz_header, "x-amz-meta-status-code")
self.check_ok_header(is_amz_header, "x-amz-server-side-encryption")

def test_is_not_amz_header(self):
self.check_bad_header(is_amz_header, "X_AMZ_META-VALUE")
self.check_bad_header(is_amz_header, "content-type")

def test_is_storageclass_header(self):
eq_(is_storageclass_header("x-amz-storage-classs"),False)
eq_(is_storageclass_header("x-amz-storage-class"),True)
self.check_ok_header(is_storageclass_header, "x-amz-storage-class")

def test_is_not_storageclass_header(self):
self.check_bad_header(is_storageclass_header, "x-amz-storage-classs")

def test_amzprefix_user_metadata(self):
metadata = {
'x-amz-meta-testing': 'values',
Expand All @@ -52,8 +127,9 @@ def test_amzprefix_user_metadata(self):
'content-language':'fr'
}
m = amzprefix_user_metadata(metadata)
self.assertTrue('X-Amz-Meta-hhh',m)
self.assertTrue('Content-Type',m)
self.assertTrue('x-amz-storage-class',m)
self.assertTrue('content-language',m)
self.assertTrue('X-Amz-Meta-amz-meta-setting',m)
self.assertTrue('Content-Type' in m)
self.assertTrue('content-language' in m)

self.assertTrue('X-Amz-Meta-hhh' in m)
self.assertTrue('x-amz-storage-class' in m)
self.assertTrue('X-Amz-Meta-amz-meta-setting' in m)

0 comments on commit 897e014

Please sign in to comment.