diff --git a/httpretty/core.py b/httpretty/core.py index 3f861b8..de7b93b 100644 --- a/httpretty/core.py +++ b/httpretty/core.py @@ -622,6 +622,7 @@ class Entry(BaseClass): if got is None: continue + igot = None try: igot = int(got) except (ValueError, TypeError): @@ -630,7 +631,7 @@ class Entry(BaseClass): 'with "%r" which is not a number' % got) return - if igot > self.body_length: + if igot and igot > self.body_length: raise HTTPrettyError( 'HTTPretty got inconsistent parameters. The header ' 'Content-Length you registered expects size "%d" but ' diff --git a/tests/functional/test_urllib2.py b/tests/functional/test_urllib2.py index cd69356..dde54a3 100644 --- a/tests/functional/test_urllib2.py +++ b/tests/functional/test_urllib2.py @@ -133,6 +133,7 @@ def test_httpretty_should_allow_forcing_headers_urllib2(): body="this is supposed to be the response", forcing_headers={ 'Content-Type': 'application/xml', + 'Content-Length': '35a', }) request = urlopen('http://github.com') @@ -141,6 +142,7 @@ def test_httpretty_should_allow_forcing_headers_urllib2(): expect(headers).to.equal({ 'content-type': 'application/xml', + 'content-length': '35a', })