CONTENT-LENGTH not being set

196 views
Skip to first unread message

Martin Ostrovsky

unread,
May 13, 2006, 12:11:55 PM5/13/06
to Django developers
Hello,

Is there a reason why CONTENT-LENGTH is always blank in the environ
dictionary that gets passed to WSGIRequest ?
(django/core/handlers/wsgi.py)

Why isn't it just automatically computed based on the length of the
request's content?

The reason I ask is because I'm getting an exception raised on line 119
in wsgi.py when the WSGI object tries to return its raw post data:

self._raw_post_data =
self.environ['wsgi.input'].read(int(self.environ["CONTENT_LENGTH"]))
ValueError: invalid literal for int():

, which fails because of the empty string value.

Thanks,
Martin

Malcolm Tredinnick

unread,
May 13, 2006, 9:42:48 PM5/13/06
to django-d...@googlegroups.com
On Sat, 2006-05-13 at 09:11 -0700, Martin Ostrovsky wrote:
> Hello,
>
> Is there a reason why CONTENT-LENGTH is always blank in the environ
> dictionary that gets passed to WSGIRequest ?
> (django/core/handlers/wsgi.py)

What web server front-end are you using to handle the request?
Development server? Twisted? Other?

>
> Why isn't it just automatically computed based on the length of the
> request's content?

I'm not sure in this specific case, but in general this is not going to
always be possible. For example, if the incoming content is passed to
the handler before it is fully received (streaming input). Django does
not have good streaming input handling at the moment, so that will not
be the case here, but I just want to point out that the solution is not
necessarily as simple as this.

>
> The reason I ask is because I'm getting an exception raised on line 119
> in wsgi.py when the WSGI object tries to return its raw post data:
>
> self._raw_post_data =
> self.environ['wsgi.input'].read(int(self.environ["CONTENT_LENGTH"]))
> ValueError: invalid literal for int():
>
> , which fails because of the empty string value.

On all requests, or only on a particular type of request?

Regards,
Malcolm

Adrian Holovaty

unread,
May 14, 2006, 2:01:00 PM5/14/06
to django-d...@googlegroups.com
On 5/13/06, Martin Ostrovsky <martin.o...@gmail.com> wrote:
> Is there a reason why CONTENT-LENGTH is always blank in the environ
> dictionary that gets passed to WSGIRequest ?
> (django/core/handlers/wsgi.py)

If you want to set the "content-length" header, use the
ConditionalGetMiddleware middleware component.

http://www.djangoproject.com/documentation/middleware/#django-middleware-http-conditionalgetmiddleware

Django doesn't do this by default for performance.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com

Reply all
Reply to author
Forward
0 new messages