diff --git a/requests/utils.py b/requests/utils.py index 118e7e1b..44b3e016 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -453,20 +453,12 @@ def _parse_content_type_header(header): :return: tuple containing content type and dictionary of parameters """ - if not header: - return None - # append delimiter on end to ensure at least two elements when split by ';' - header += ';' - # split content type's main value from params - tokens = header.split(';', 1) - content_type_index = 0 - params_index = 1 - content_type = tokens[content_type_index].strip() - params = tokens[params_index] - params_dict = dict() + tokens = header.split(';') + content_type, params = tokens[0].strip(), tokens[1:] + params_dict = {} # Using dict is actually slower than a dictionary literal. Weird but tru - for param in params.split(';'): + for param in params: if param and not param.isspace(): param = param.strip() key, value = param, True @@ -476,6 +468,7 @@ def _parse_content_type_header(header): params_dict[key] = value return content_type, params_dict + def get_encoding_from_headers(headers): """Returns encodings from given HTTP Header Dict. diff --git a/tests/test_utils.py b/tests/test_utils.py index e734b8f8..f89d15aa 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -472,14 +472,6 @@ def test_parse_dict_header(value, expected): @pytest.mark.parametrize( 'value, expected', ( - ( - None, - None - ), -( - '', - None - ), ( 'application/xml', ('application/xml', dict())