Example #1
0
    def test_request_httprepr(self):
        r1 = Request("http://www.example.com")
        self.assertEqual(request_httprepr(r1), b'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), b'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": b"text/html"}, body=b"Some body")
        self.assertEqual(request_httprepr(r1), b'POST / HTTP/1.1\r\nHost: www.example.com\r\nContent-Type: text/html\r\n\r\nSome body')
Example #2
0
    def test_request_httprepr(self):
        r1 = Request("http://www.example.com")
        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")
        self.assertEqual(request_httprepr(r1), 'POST / HTTP/1.1\r\nHost: www.example.com\r\nContent-Type: text/html\r\n\r\nSome body')
Example #3
0
 def process_request(self, request, spider):
     self.stats.inc_value('downloader/request_count', spider=spider)
     self.stats.inc_value('downloader/request_method_count/%s' %
                          request.method,
                          spider=spider)
     reqlen = len(request_httprepr(request))
     self.stats.inc_value('downloader/request_bytes', reqlen, spider=spider)
Example #4
0
 def process_request(self, request, spider):
     stats.inc_value('downloader/request_count')
     stats.inc_value('downloader/request_count', spider=spider)
     stats.inc_value('downloader/request_method_count/%s' % request.method, spider=spider)
     reqlen = len(request_httprepr(request))
     stats.inc_value('downloader/request_bytes', reqlen, spider=spider)
     stats.inc_value('downloader/request_bytes', reqlen)
Example #5
0
 def process_request(self, request, spider):
     domain = _get_domain_from_url(request.url)
     self.stats.inc_value('downloader/%s/request_count' % domain,
                          spider=spider)
     self.stats.inc_value('downloader/%s/request_method_count/%s' %
                          (domain, request.method),
                          spider=spider)
     reqlen = len(request_httprepr(request))
     self.stats.inc_value('downloader/%s/request_bytes' % domain,
                          reqlen,
                          spider=spider)
Example #6
0
 def process_request(self, request, spider):
     proxy = get_request_proxy(request)
     if proxy:
         self.stats.inc_value('downloader/proxy/%s/request_count' % proxy,
                              spider=spider)
         self.stats.inc_value(
             'downloader/proxy/%s/request_method_count/%s' %
             (proxy, request.method),
             spider=spider)
         reqlen = len(request_httprepr(request))
         self.stats.inc_value('downloader/proxy/%s/request_bytes' % proxy,
                              reqlen,
                              spider=spider)
Example #7
0
 def test_request_httprepr_for_non_http_request(self):
     # the representation is not important but it must not fail.
     request_httprepr(Request("file:///tmp/foo.txt"))
     request_httprepr(Request("ftp://localhost/tmp/foo.txt"))
Example #8
0
 def process_request(self, request, spider):
     self.stats.inc_value("downloader/request_count", spider=spider)
     self.stats.inc_value(
         f"downloader/request_method_count/{request.method}", spider=spider)
     reqlen = len(request_httprepr(request))
     self.stats.inc_value("downloader/request_bytes", reqlen, spider=spider)
Example #9
0
 def process_request(self, request, spider):
     self.stats.inc_value('downloader/request_count', spider=spider)
     self.stats.inc_value('downloader/request_method_count/{0!s}'.format(request.method), spider=spider)
     reqlen = len(request_httprepr(request))
     self.stats.inc_value('downloader/request_bytes', reqlen, spider=spider)
Example #10
0
 def test_request_httprepr_for_non_http_request(self):
     # the representation is not important but it must not fail.
     request_httprepr(Request("file:///tmp/foo.txt"))
     request_httprepr(Request("ftp://localhost/tmp/foo.txt"))