preserve content-type parameter order

This commit is contained in:
Maximilian Hils 2016-07-15 23:46:12 -07:00
parent 3602fd7a36
commit e6e39ce80f
2 changed files with 5 additions and 2 deletions

View File

@ -2,6 +2,7 @@ from __future__ import absolute_import, print_function, division
import re
import collections
import six
from netlib import multidict
from netlib import strutils
@ -206,7 +207,7 @@ def parse_content_type(c):
ts = parts[0].split("/", 1)
if len(ts) != 2:
return None
d = {}
d = collections.OrderedDict()
if len(parts) == 2:
for i in parts[1].split(";"):
clause = i.split("=", 1)

View File

@ -1,3 +1,5 @@
import collections
from netlib.http.headers import Headers, parse_content_type, assemble_content_type
from netlib.tutils import raises
@ -87,4 +89,4 @@ def test_assemble_content_type():
p = assemble_content_type
assert p("text", "html", {}) == "text/html"
assert p("text", "html", {"charset": "utf8"}) == "text/html; charset=utf8"
assert p("text", "html", {"charset": "utf8", "foo": "bar"}) == "text/html; charset=utf8; foo=bar"
assert p("text", "html", collections.OrderedDict([("charset", "utf8"), ("foo", "bar")])) == "text/html; charset=utf8; foo=bar"