From 99e3c0d653e23d1af3e4236b88a747317e1c8a8a Mon Sep 17 00:00:00 2001 From: Paul Tremberth Date: Thu, 23 Mar 2017 11:52:01 +0100 Subject: [PATCH] Set bodyproducer with empty content for POST --- scrapy/core/downloader/handlers/http11.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/scrapy/core/downloader/handlers/http11.py b/scrapy/core/downloader/handlers/http11.py index 37e836809..bff4a30c9 100644 --- a/scrapy/core/downloader/handlers/http11.py +++ b/scrapy/core/downloader/handlers/http11.py @@ -280,19 +280,7 @@ class ScrapyAgent(object): if request.body: bodyproducer = _RequestBodyProducer(request.body) else: - bodyproducer = None - # Setting Content-Length: 0 even for POST requests is not a - # MUST per HTTP RFCs, but it's common behavior, and some - # servers require this, otherwise returning HTTP 411 Length required - # - # RFC 7230#section-3.3.2: - # "a Content-Length header field is normally sent in a POST - # request even when the value is 0 (indicating an empty payload body)." - # - # Twisted Agent will not add "Content-Length: 0" by itself - if method == b'POST': - headers.addRawHeader(b'Content-Length', b'0') - + bodyproducer = _RequestBodyProducer(b'') if method == b'POST' else None start_time = time() d = agent.request( method, to_bytes(url, encoding='ascii'), headers, bodyproducer)