mirror of https://github.com/scrapy/scrapy.git
bugfix in request_httprepr() function
This commit is contained in:
parent
ec850b9fd1
commit
b8aa74ee9e
|
|
@ -63,10 +63,13 @@ class UtilsRequestTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_request_httprepr(self):
|
def test_request_httprepr(self):
|
||||||
r1 = Request("http://www.example.com")
|
r1 = Request("http://www.example.com")
|
||||||
self.assertEqual(request_httprepr(r1), 'GET http://www.example.com HTTP/1.1\r\nHost: www.example.com\r\n\r\n')
|
self.assertEqual(request_httprepr(r1), 'GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n')
|
||||||
|
|
||||||
|
r1 = Request("http://www.example.com/some/page.html?arg=1")
|
||||||
|
self.assertEqual(request_httprepr(r1), 'GET /some/page.html?arg=1 HTTP/1.1\r\nHost: www.example.com\r\n\r\n')
|
||||||
|
|
||||||
r1 = Request("http://www.example.com", method='POST', headers={"Content-type": "text/html"}, body="Some body")
|
r1 = Request("http://www.example.com", method='POST', headers={"Content-type": "text/html"}, body="Some body")
|
||||||
self.assertEqual(request_httprepr(r1), 'POST http://www.example.com HTTP/1.1\r\nHost: www.example.com\r\nContent-Type: text/html\r\n\r\nSome body')
|
self.assertEqual(request_httprepr(r1), 'POST / HTTP/1.1\r\nHost: www.example.com\r\nContent-Type: text/html\r\n\r\nSome body')
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ scrapy.http.Request objects
|
||||||
import hashlib
|
import hashlib
|
||||||
import weakref
|
import weakref
|
||||||
from base64 import urlsafe_b64encode
|
from base64 import urlsafe_b64encode
|
||||||
|
from urlparse import urlunparse
|
||||||
|
|
||||||
from scrapy.utils.url import canonicalize_url
|
from scrapy.utils.url import canonicalize_url
|
||||||
from scrapy.utils.httpobj import urlparse_cached
|
from scrapy.utils.httpobj import urlparse_cached
|
||||||
|
|
@ -76,9 +77,10 @@ def request_httprepr(request):
|
||||||
bytes that will be send when performing the request (that's controlled
|
bytes that will be send when performing the request (that's controlled
|
||||||
by Twisted).
|
by Twisted).
|
||||||
"""
|
"""
|
||||||
hostname = urlparse_cached(request).hostname
|
parsed = urlparse_cached(request)
|
||||||
s = "%s %s HTTP/1.1\r\n" % (request.method, request.url)
|
path = urlunparse(('', '', parsed.path or '/', parsed.params, parsed.query, ''))
|
||||||
s += "Host: %s\r\n" % hostname
|
s = "%s %s HTTP/1.1\r\n" % (request.method, path)
|
||||||
|
s += "Host: %s\r\n" % parsed.hostname
|
||||||
if request.headers:
|
if request.headers:
|
||||||
s += request.headers.to_string() + "\r\n"
|
s += request.headers.to_string() + "\r\n"
|
||||||
s += "\r\n"
|
s += "\r\n"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue