Avoid sending Content-Length header when body is an empty string.

Some sites can't handle "Content-Length: 0" header, but twisted
HTTPClientFactory adds Content-Length header unless body is None.

scrapy enforces request.body usage as string, using None is not
possible.

thanks Matt for report, See:
http://groups.google.com/group/scrapy-users/browse_thread/thread/380ffa111879989e?hl=en

--HG--
extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40841
This commit is contained in:
Daniel Grana 2009-02-10 13:23:38 +00:00
parent f4224be411
commit 8fdf06ed08
2 changed files with 5 additions and 3 deletions

View File

@ -41,8 +41,10 @@ Request objects
``meta`` is a dict containing the initial values for the
:attr:`Request.meta` attribute. If passed, the dict will be shallow copied.
``body`` is a str or unicode containing the request body. If ``body`` is
a `unicode` it's encoded to str using the `encoding` passed.
``body`` is a str or unicode containing the request body.
If ``body`` is a `unicode` it's encoded to str using the `encoding` passed.
If ``body`` is None, an empty string is stored.
In any case, the final stored value will be a string (never unicode, never None).
``headers`` is a multi-valued dict containing the headers of this request

View File

@ -53,7 +53,7 @@ def create_factory(request, spider):
agent = request.headers.pop('user-agent', default_agent)
factory = HTTPClientFactory(url=url, # never pass unicode urls to twisted
method=request.method,
postdata=request.body,
postdata=request.body or None,
headers=request.headers,
agent=agent,
cookies=request.cookies,