Skip to content

Commit

Permalink
bug fix for quantmind#178
Browse files Browse the repository at this point in the history
  • Loading branch information
lsbardel committed Nov 14, 2015
1 parent 7d01edc commit d50abfc
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
17 changes: 9 additions & 8 deletions pulsar/utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
'''
import traceback

from .httpurl import Headers


__all__ = ['PulsarException',
'MonitorStarted',
'ImproperlyConfigured',
Expand Down Expand Up @@ -121,13 +124,13 @@ def __init__(self, msg='', status=None, handler=None, strict=False,
self.code = self.status # for compatibility with HTTPError
self.handler = handler
self.strict = strict
self.headers = headers
self.content_type = content_type
self._headers = Headers.make(headers)
super().__init__(msg)

@property
def hdrs(self):
return self.headers
def headers(self):
return list(self._headers)


class HttpRedirect(HttpException):
Expand All @@ -138,17 +141,15 @@ class HttpRedirect(HttpException):
status = 302

def __init__(self, location, status=None, headers=None, **kw):
headers = [] if headers is None else headers
headers.append(('location', location))
headers = Headers.make(headers)
headers['location'] = location
super().__init__(status=status or self.status, headers=headers, **kw)

@property
def location(self):
'''The value in the ``Location`` header entry.
Equivalent to ``self.headers['location']``.
'''
return self.headers['location']
return self._headers['location']


class BadRequest(HttpException):
Expand Down
8 changes: 7 additions & 1 deletion pulsar/utils/httpurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def parse_options_header(header, options=None):
return ctype, options


class Headers(object):
class Headers:
'''Utility for managing HTTP headers for both clients and servers.
It has a dictionary like interface with few extra functions to facilitate
Expand Down Expand Up @@ -511,6 +511,12 @@ class Headers(object):
The strict parameter is rarely used and it forces the omission on
non-standard header fields.
'''
@classmethod
def make(cls, headers):
if not isinstance(headers, cls):
headers = cls(headers=headers)
return headers

def __init__(self, headers=None, kind='server', strict=False):
if isinstance(kind, int):
kind = header_type.get(kind, 'both')
Expand Down
1 change: 1 addition & 0 deletions release/notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Bug fix in ``HttpRedirect.location`` attribute
4 changes: 4 additions & 0 deletions release/release.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tag_name": "1.0.6",
"name": ""
}
14 changes: 14 additions & 0 deletions tests/wsgi/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import unittest

from pulsar import HttpRedirect


class WsgiRequestTests(unittest.TestCase):

def test_httpredirect(self):
location = 'https://pythonhosted.org/pulsar'
r = HttpRedirect(location)
self.assertEqual(r.location, location)
r = HttpRedirect(location, headers=[('Content-Type', 'text/html')])
self.assertEqual(len(r.headers), 2)
self.assertEqual(r.location, location)

0 comments on commit d50abfc

Please sign in to comment.