Skip to content

Commit 3f7a5dd

Browse files
authored
Merge pull request #1517 from billyrrr/fix/unauthorized-init
Fix #1516 initialization of Unauthorized with www_authenticate=None
2 parents ce45413 + 4ee2464 commit 3f7a5dd

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

CHANGES.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Unreleased
99
Python 2.7. (:issue:`1080`)
1010
- Restore the ``response`` argument to :exc:`exceptions.Unauthorized`.
1111
(:pr:`1527`)
12+
- :exc:`exceptions.Unauthorized` doesn't add the ``WWW-Authenticate``
13+
header if ``www_authenticate`` is not given. (:issue:`1516`)
1214
- The default URL converter correctly encodes bytes to string rather
1315
than representing them with ``b''``. (:issue:`1502`)
1416

@@ -38,7 +40,7 @@ Version 0.15.1
3840

3941
Released 2019-03-21
4042

41-
- :class:`~exceptions.Unauthorized` takes ``description`` as the first
43+
- :exc:`~exceptions.Unauthorized` takes ``description`` as the first
4244
argument, restoring previous behavior. The new ``www_authenticate``
4345
argument is listed second. (:issue:`1483`)
4446

src/werkzeug/exceptions.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,12 @@ class Unauthorized(HTTPException):
251251
:param www-authenticate: A single value, or list of values, for the
252252
WWW-Authenticate header.
253253
254-
.. versionchanged:: 0.15.2
254+
.. versionchanged:: 0.15.3
255+
If the ``www_authenticate`` argument is not set, the
256+
``WWW-Authenticate`` header is not set.
257+
258+
.. versionchanged:: 0.15.3
259+
The ``response`` argument was restored.
255260
256261
.. versionchanged:: 0.15.1
257262
``description`` was moved back as the first argument, restoring
@@ -272,8 +277,11 @@ class Unauthorized(HTTPException):
272277

273278
def __init__(self, description=None, response=None, www_authenticate=None):
274279
HTTPException.__init__(self, description, response)
275-
if not isinstance(www_authenticate, (tuple, list)):
276-
www_authenticate = (www_authenticate,)
280+
281+
if www_authenticate is not None:
282+
if not isinstance(www_authenticate, (tuple, list)):
283+
www_authenticate = (www_authenticate,)
284+
277285
self.www_authenticate = www_authenticate
278286

279287
def get_headers(self, environ=None):

tests/test_exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,7 @@ def test_unauthorized_www_authenticate():
110110
exc = exceptions.Unauthorized(www_authenticate=[digest, basic])
111111
h = dict(exc.get_headers({}))
112112
assert h["WWW-Authenticate"] == ", ".join((str(digest), str(basic)))
113+
114+
exc = exceptions.Unauthorized()
115+
h = dict(exc.get_headers({}))
116+
assert "WWW-Authenticate" not in h

0 commit comments

Comments
 (0)