aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/http/headers.py
diff options
context:
space:
mode:
Diffstat (limited to 'netlib/http/headers.py')
-rw-r--r--netlib/http/headers.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/netlib/http/headers.py b/netlib/http/headers.py
index c8cf3e43..36e5060c 100644
--- a/netlib/http/headers.py
+++ b/netlib/http/headers.py
@@ -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,10 +207,22 @@ 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)
if len(clause) == 2:
d[clause[0].strip()] = clause[1].strip()
return ts[0].lower(), ts[1].lower(), d
+
+
+def assemble_content_type(type, subtype, parameters):
+ if not parameters:
+ return "{}/{}".format(type, subtype)
+ params = "; ".join(
+ "{}={}".format(k, v)
+ for k, v in parameters.items()
+ )
+ return "{}/{}; {}".format(
+ type, subtype, params
+ )