diff --git a/scrapy/trunk/docs/ref/downloader-middleware.rst b/scrapy/trunk/docs/ref/downloader-middleware.rst index c2285320c..8665e78be 100644 --- a/scrapy/trunk/docs/ref/downloader-middleware.rst +++ b/scrapy/trunk/docs/ref/downloader-middleware.rst @@ -34,6 +34,9 @@ thus it's recommended to leave it always enabled. Those tasks are: * If the request method is ``POST`` and the ``Content-Type`` header is not set, then set it to ``'application/x-www-form-urlencoded'``, the `default Form content type`_. + + * If the request contains a body and the ``Content-Length`` headers it not + set, then set it to the ``len(body)``. .. _default Form content type: http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1 diff --git a/scrapy/trunk/scrapy/contrib/downloadermiddleware/common.py b/scrapy/trunk/scrapy/contrib/downloadermiddleware/common.py index 91d95496c..793ed85ed 100644 --- a/scrapy/trunk/scrapy/contrib/downloadermiddleware/common.py +++ b/scrapy/trunk/scrapy/contrib/downloadermiddleware/common.py @@ -17,4 +17,6 @@ class CommonMiddleware(object): request.headers.setdefault('Accept-Language', self.header_accept_language) if request.method == 'POST': request.headers.setdefault('Content-Type', 'application/x-www-form-urlencoded') + if request.body: + request.headers.setdefault('Content-Length', '%d' % len(request.body))