It's not very obvious from the docs or source if HttpRequest.read() can 
always be safely treated as a limited input stream, or if the developer 
needs to respect HttpRequest.META['CONTENT_LENGTH'].

As far as I can tell the intention is that it can always be treated as a 
limited stream, that seems to at least be the implication in 
WSGIRequest.__init__, in which case it looks to me like there are two bugs.

1. This code should not raise an Assertion Error...

>>> from django.test.client import RequestFactory
>>> req=RequestFactory().post('/', {'foo':'bar'})
>>> req.read(9999)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File 
"/Users/tomchristie/workspace/django-rest-framework/env/lib/python2.6/site-packages/django/http/__init__.py",
 
line 296, in read
    return self._stream.read(*args, **kwargs)
  File 
"/Users/tomchristie/workspace/django-rest-framework/env/lib/python2.6/site-packages/django/test/client.py",
 
line 51, in read
    assert self.__len >= num_bytes, "Cannot read more than the available 
bytes from the HTTP incoming data."
AssertionError: Cannot read more than the available bytes from the HTTP 
incoming data.

After all, running under the dev server I can do this just fine without 
causing an exception:

def test(request):
    return HttpResponse("Read data: '%s'\n" % request.read(9999))

(In the first case the underlying stream isn't being wrapped in a 
LimitedStream, in the second case it is)

2. Isn't the use of LimitBytes in MultipartParser.parse() now redundant?

If it isn't the intention that HttpRequest.read() can be treated as a 
limited stream then shouldn't this be documented, and in any case wouldn't 
it be better if it was always a limited stream - there's some 
duplicated behavior with parsing the CONTENT_LENGTH in WSGIRequest, 
HttpRequest and MultipartParser that looks like ti could be avoided.

Am I just fundamentally misunderstanding something?

Cheers,

  Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to