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:
@@ -35,7 +35,7 @@ from swift.common.utils import get_logger, get_param, hash_path, public, \
|
|||||||
normalize_timestamp, split_path, storage_directory, TRUE_VALUES, \
|
normalize_timestamp, split_path, storage_directory, TRUE_VALUES, \
|
||||||
validate_device_partition
|
validate_device_partition
|
||||||
from swift.common.constraints import ACCOUNT_LISTING_LIMIT, \
|
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.db_replicator import ReplicatorRpc
|
||||||
from swift.common.http import HTTPInsufficientStorage
|
from swift.common.http import HTTPInsufficientStorage
|
||||||
|
|
||||||
@@ -252,8 +252,8 @@ class AccountController(object):
|
|||||||
return HTTPBadRequest(body='parameters not utf8',
|
return HTTPBadRequest(body='parameters not utf8',
|
||||||
content_type='text/plain', request=req)
|
content_type='text/plain', request=req)
|
||||||
if query_format:
|
if query_format:
|
||||||
qfmt_lower = query_format.lower()
|
req.accept = FORMAT2CONTENT_TYPE.get(query_format.lower(),
|
||||||
req.accept = 'application/%s' % qfmt_lower
|
FORMAT2CONTENT_TYPE['plain'])
|
||||||
try:
|
try:
|
||||||
out_content_type = req.accept.best_match(
|
out_content_type = req.accept.best_match(
|
||||||
['text/plain', 'application/json',
|
['text/plain', 'application/json',
|
||||||
|
@@ -37,6 +37,9 @@ CONTAINER_LISTING_LIMIT = 10000
|
|||||||
ACCOUNT_LISTING_LIMIT = 10000
|
ACCOUNT_LISTING_LIMIT = 10000
|
||||||
MAX_ACCOUNT_NAME_LENGTH = 256
|
MAX_ACCOUNT_NAME_LENGTH = 256
|
||||||
MAX_CONTAINER_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):
|
def check_metadata(req, target_type):
|
||||||
|
@@ -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, \
|
normalize_timestamp, storage_directory, split_path, validate_sync_to, \
|
||||||
TRUE_VALUES, validate_device_partition
|
TRUE_VALUES, validate_device_partition
|
||||||
from swift.common.constraints import CONTAINER_LISTING_LIMIT, \
|
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.bufferedhttp import http_connect
|
||||||
from swift.common.exceptions import ConnectionTimeout
|
from swift.common.exceptions import ConnectionTimeout
|
||||||
from swift.common.db_replicator import ReplicatorRpc
|
from swift.common.db_replicator import ReplicatorRpc
|
||||||
@@ -348,8 +348,8 @@ class ContainerController(object):
|
|||||||
return HTTPBadRequest(body='parameters not utf8',
|
return HTTPBadRequest(body='parameters not utf8',
|
||||||
content_type='text/plain', request=req)
|
content_type='text/plain', request=req)
|
||||||
if query_format:
|
if query_format:
|
||||||
qfmt_lower = query_format.lower()
|
req.accept = FORMAT2CONTENT_TYPE.get(query_format.lower(),
|
||||||
req.accept = 'application/%s' % qfmt_lower
|
FORMAT2CONTENT_TYPE['plain'])
|
||||||
try:
|
try:
|
||||||
out_content_type = req.accept.best_match(
|
out_content_type = req.accept.best_match(
|
||||||
['text/plain', 'application/json',
|
['text/plain', 'application/json',
|
||||||
|
Reference in New Issue
Block a user