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 e10a37e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 9 additions & 2 deletions 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 Expand Up @@ -2736,5 +2742,6 @@ def __repr__(self):
# circular dependencies
from werkzeug.http import dump_options_header, dump_header, generate_etag, \
quote_header_value, parse_set_header, unquote_etag, quote_etag, \
parse_options_header, http_date, is_byte_range_valid
parse_options_header, http_date, is_byte_range_valid, \
dump_options_header_list
from werkzeug import exceptions
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 e10a37e

Please sign in to comment.