Cleaner fix to format regression fix

This ensures req.accepts is only assigned a valid content type.

Change-Id: Idf19277959c516398d31f771cf42dec0733d1bc0
This commit is contained in:
gholt 2012-07-31 04:22:12 +00:00
parent de9b81baee
commit 0d38c710a5
3 changed files with 9 additions and 6 deletions

View File

@ -35,7 +35,7 @@ from swift.common.utils import get_logger, get_param, hash_path, public, \
normalize_timestamp, split_path, storage_directory, TRUE_VALUES, \
validate_device_partition
from swift.common.constraints import ACCOUNT_LISTING_LIMIT, \
check_mount, check_float, check_utf8
check_mount, check_float, check_utf8, FORMAT2CONTENT_TYPE
from swift.common.db_replicator import ReplicatorRpc
from swift.common.http import HTTPInsufficientStorage
@ -252,8 +252,8 @@ class AccountController(object):
return HTTPBadRequest(body='parameters not utf8',
content_type='text/plain', request=req)
if query_format:
qfmt_lower = query_format.lower()
req.accept = 'application/%s' % qfmt_lower
req.accept = FORMAT2CONTENT_TYPE.get(query_format.lower(),
FORMAT2CONTENT_TYPE['plain'])
try:
out_content_type = req.accept.best_match(
['text/plain', 'application/json',

View File

@ -37,6 +37,9 @@ CONTAINER_LISTING_LIMIT = 10000
ACCOUNT_LISTING_LIMIT = 10000
MAX_ACCOUNT_NAME_LENGTH = 256
MAX_CONTAINER_NAME_LENGTH = 256
#: Query string format= values to their corresponding content-type values
FORMAT2CONTENT_TYPE = {'plain': 'text/plain', 'json': 'application/json',
'xml': 'application/xml'}
def check_metadata(req, target_type):

View File

@ -35,7 +35,7 @@ from swift.common.utils import get_logger, get_param, hash_path, public, \
normalize_timestamp, storage_directory, split_path, validate_sync_to, \
TRUE_VALUES, validate_device_partition
from swift.common.constraints import CONTAINER_LISTING_LIMIT, \
check_mount, check_float, check_utf8
check_mount, check_float, check_utf8, FORMAT2CONTENT_TYPE
from swift.common.bufferedhttp import http_connect
from swift.common.exceptions import ConnectionTimeout
from swift.common.db_replicator import ReplicatorRpc
@ -348,8 +348,8 @@ class ContainerController(object):
return HTTPBadRequest(body='parameters not utf8',
content_type='text/plain', request=req)
if query_format:
qfmt_lower = query_format.lower()
req.accept = 'application/%s' % qfmt_lower
req.accept = FORMAT2CONTENT_TYPE.get(query_format.lower(),
FORMAT2CONTENT_TYPE['plain'])
try:
out_content_type = req.accept.best_match(
['text/plain', 'application/json',