Skip to content

Commit

Permalink
Fix #289 - Website should work with wsgiref
Browse files Browse the repository at this point in the history
We were read()ing when there were no bytes expected,
which meant we blocked when we shouldn't have.
  • Loading branch information
pjz committed Apr 1, 2014
1 parent 0f9f845 commit 943cb8a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions aspen/http/request.py
Expand Up @@ -631,7 +631,8 @@ def __init__(self, headers, fp, server_software):
"""
typecheck(headers, Headers, server_software, str)
self.raw = self._read_raw(server_software, fp) # XXX lazy!
raw_len = int(headers.get('Content-length', '') or '0')
self.raw = self._read_raw(server_software, fp, raw_len) # XXX lazy!
parsed = self._parse(headers, self.raw)
if parsed is None:
# There was no content-type. Use self.raw.
Expand All @@ -648,11 +649,11 @@ def __init__(self, headers, fp, server_software):
self[k] = v


def _read_raw(self, server_software, fp):
"""Given str and a file-like object, return a bytestring.
def _read_raw(self, server_software, fp, raw_len):
"""Given str, a file-like object, and the number of expected bytes, return a bytestring.
"""
if not server_software.startswith('Rocket'): # normal
raw = fp.read()
raw = fp.read(raw_len)
else: # rocket

# Email from Rocket guy: While HTTP stipulates that you shouldn't
Expand Down Expand Up @@ -682,7 +683,7 @@ def _read_raw(self, server_software, fp):
_tmp = fp._sock.timeout
fp._sock.settimeout(0) # equiv. to non-blocking
try:
raw = fp.read()
raw = fp.read(raw_len)
except Exception, exc:
if exc.errno != 35:
raise
Expand Down

0 comments on commit 943cb8a

Please sign in to comment.