Skip to content

Commit

Permalink
Allow Headers.add to get a list of parameters on *args
Browse files Browse the repository at this point in the history
This ensures the order of parameters, which can be useful for issues
like supporting IE8 in flask's #2223
  • Loading branch information
antlarr committed Apr 7, 2017
1 parent ee959e2 commit cdfacb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion werkzeug/datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ def __iter__(self):
def __len__(self):
return len(self._list)

def add(self, _key, _value, **kw):
def add(self, _key, _value, *args, **kw):
"""Add a new header tuple to the list.
Keyword arguments can specify additional parameters for the header
Expand All @@ -1153,9 +1153,15 @@ def add(self, _key, _value, **kw):
The keyword argument dumping uses :func:`dump_options_header`
behind the scenes.
In some cases, it would be needed to ensure the order of parameters.
For those cases, a list of ``(key, value)`` tuples can be passed in
*args.
.. versionadded:: 0.4.1
keyword arguments were added for :mod:`wsgiref` compatibility.
"""
if args:
_value = dump_options_header(_value, args)
if kw:
_value = _options_header_vkw(_value, kw)
_value = _unicodify_header_value(_value)
Expand Down
6 changes: 5 additions & 1 deletion werkzeug/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ def dump_options_header(header, options):
segments = []
if header is not None:
segments.append(header)
for key, value in iteritems(options):
if isinstance(options, tuple):
iter_func = iter
else:
iter_func = iteritems
for key, value in iter_func(options):
if value is None:
segments.append(key)
else:
Expand Down

0 comments on commit cdfacb4

Please sign in to comment.