Merge "Tell swift to figure out content type"
This commit is contained in:
commit
948d34f3db
@ -875,11 +875,17 @@ class ObjectController(Controller):
|
|||||||
req.headers['X-Timestamp'] = normalize_timestamp(time.time())
|
req.headers['X-Timestamp'] = normalize_timestamp(time.time())
|
||||||
# Sometimes the 'content-type' header exists, but is set to None.
|
# Sometimes the 'content-type' header exists, but is set to None.
|
||||||
content_type_manually_set = True
|
content_type_manually_set = True
|
||||||
if not req.headers.get('content-type'):
|
detect_content_type = \
|
||||||
|
config_true_value(req.headers.get('x-detect-content-type'))
|
||||||
|
if detect_content_type or not req.headers.get('content-type'):
|
||||||
guessed_type, _junk = mimetypes.guess_type(req.path_info)
|
guessed_type, _junk = mimetypes.guess_type(req.path_info)
|
||||||
req.headers['Content-Type'] = guessed_type or \
|
req.headers['Content-Type'] = guessed_type or \
|
||||||
'application/octet-stream'
|
'application/octet-stream'
|
||||||
|
if detect_content_type:
|
||||||
|
req.headers.pop('x-detect-content-type')
|
||||||
|
else:
|
||||||
content_type_manually_set = False
|
content_type_manually_set = False
|
||||||
|
|
||||||
error_response = check_object_creation(req, self.object_name) or \
|
error_response = check_object_creation(req, self.object_name) or \
|
||||||
check_content_type(req)
|
check_content_type(req)
|
||||||
if error_response:
|
if error_response:
|
||||||
|
@ -2036,6 +2036,53 @@ class TestObjectController(unittest.TestCase):
|
|||||||
res = controller.POST(req)
|
res = controller.POST(req)
|
||||||
self.assertEquals(res.status_int, 400)
|
self.assertEquals(res.status_int, 400)
|
||||||
|
|
||||||
|
def test_PUT_not_autodetect_content_type(self):
|
||||||
|
with save_globals():
|
||||||
|
controller = proxy_server.ObjectController(
|
||||||
|
self.app, 'a', 'c', 'o.html')
|
||||||
|
|
||||||
|
headers = {'Content-Type': 'something/right', 'Content-Length': 0}
|
||||||
|
it_worked = []
|
||||||
|
|
||||||
|
def verify_content_type(ipaddr, port, device, partition,
|
||||||
|
method, path, headers=None,
|
||||||
|
query_string=None):
|
||||||
|
if path == '/a/c/o.html':
|
||||||
|
it_worked.append(
|
||||||
|
headers['Content-Type'].startswith('something/right'))
|
||||||
|
|
||||||
|
set_http_connect(204, 204, 201, 201, 201,
|
||||||
|
give_connect=verify_content_type)
|
||||||
|
req = Request.blank('/a/c/o.html', {}, headers=headers)
|
||||||
|
self.app.update_request(req)
|
||||||
|
res = controller.PUT(req)
|
||||||
|
self.assertNotEquals(it_worked, [])
|
||||||
|
self.assertTrue(all(it_worked))
|
||||||
|
|
||||||
|
def test_PUT_autodetect_content_type(self):
|
||||||
|
with save_globals():
|
||||||
|
controller = proxy_server.ObjectController(
|
||||||
|
self.app, 'a', 'c', 'o.html')
|
||||||
|
|
||||||
|
headers = {'Content-Type': 'something/wrong', 'Content-Length': 0,
|
||||||
|
'X-Detect-Content-Type': 'True'}
|
||||||
|
it_worked = []
|
||||||
|
|
||||||
|
def verify_content_type(ipaddr, port, device, partition,
|
||||||
|
method, path, headers=None,
|
||||||
|
query_string=None):
|
||||||
|
if path == '/a/c/o.html':
|
||||||
|
it_worked.append(
|
||||||
|
headers['Content-Type'].startswith('text/html'))
|
||||||
|
|
||||||
|
set_http_connect(204, 204, 201, 201, 201,
|
||||||
|
give_connect=verify_content_type)
|
||||||
|
req = Request.blank('/a/c/o.html', {}, headers=headers)
|
||||||
|
self.app.update_request(req)
|
||||||
|
res = controller.PUT(req)
|
||||||
|
self.assertNotEquals(it_worked, [])
|
||||||
|
self.assertTrue(all(it_worked))
|
||||||
|
|
||||||
def test_client_timeout(self):
|
def test_client_timeout(self):
|
||||||
with save_globals():
|
with save_globals():
|
||||||
self.app.account_ring.get_nodes('account')
|
self.app.account_ring.get_nodes('account')
|
||||||
|
Loading…
Reference in New Issue
Block a user