mirror of https://github.com/scrapy/scrapy.git
Merge pull request #1089 from drack3800/master
[MRG+1] Add test for webclient with POST method and no body given
This commit is contained in:
commit
ec4251afd7
|
|
@ -118,6 +118,9 @@ class ScrapyHTTPClientFactory(HTTPClientFactory):
|
|||
self.headers['Content-Length'] = len(self.body)
|
||||
# just in case a broken http/1.1 decides to keep connection alive
|
||||
self.headers.setdefault("Connection", "close")
|
||||
# Content-Length must be specified in POST method even with no body
|
||||
elif self.method == 'POST':
|
||||
self.headers['Content-Length'] = 0
|
||||
|
||||
def _build_response(self, body, request):
|
||||
request.meta['download_latency'] = self.headers_time-self.start_time
|
||||
|
|
|
|||
|
|
@ -132,6 +132,18 @@ class ScrapyHTTPPageGetterTests(unittest.TestCase):
|
|||
"\r\n"
|
||||
"name=value")
|
||||
|
||||
# test a POST method with no body provided
|
||||
factory = client.ScrapyHTTPClientFactory(Request(
|
||||
method='POST',
|
||||
url='http://foo/bar'
|
||||
))
|
||||
|
||||
self._test(factory,
|
||||
"POST /bar HTTP/1.0\r\n"
|
||||
"Host: foo\r\n"
|
||||
"Content-Length: 0\r\n"
|
||||
"\r\n")
|
||||
|
||||
# test with single and multivalued headers
|
||||
factory = client.ScrapyHTTPClientFactory(Request(
|
||||
url='http://foo/bar',
|
||||
|
|
|
|||
Loading…
Reference in New Issue