From e43f5a284f4008cd4c2383286a6d7c91584490d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Chaves?= Date: Fri, 2 Feb 2024 15:08:26 +0100 Subject: [PATCH] Use Zyte-Client (#114) --- scrapy_zyte_smartproxy/middleware.py | 6 +++--- tests/test_all.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scrapy_zyte_smartproxy/middleware.py b/scrapy_zyte_smartproxy/middleware.py index 31ef82b..e7672f0 100644 --- a/scrapy_zyte_smartproxy/middleware.py +++ b/scrapy_zyte_smartproxy/middleware.py @@ -220,9 +220,9 @@ def process_request(self, request, spider): if self.job_id: job_header = 'Zyte-JobId' if targets_zyte_api else 'X-Crawlera-JobId' request.headers[job_header] = self.job_id - if not targets_zyte_api: - from scrapy_zyte_smartproxy import __version__ - request.headers['X-Crawlera-Client'] = 'scrapy-zyte-smartproxy/%s' % __version__ + user_agent_header = "Zyte-Client" if targets_zyte_api else "X-Crawlera-Client" + from scrapy_zyte_smartproxy import __version__ + request.headers[user_agent_header] = 'scrapy-zyte-smartproxy/%s' % __version__ self.crawler.stats.inc_value('zyte_smartproxy/request') self.crawler.stats.inc_value('zyte_smartproxy/request/method/%s' % request.method) self._translate_headers(request, targets_zyte_api=targets_zyte_api) diff --git a/tests/test_all.py b/tests/test_all.py index b51abac..1fce2b7 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -983,7 +983,7 @@ def test_client_header(self): ) self.assertEqual(mw.process_request(req2, self.spider), None) self.assertEqual(req2.headers.get('X-Crawlera-Client'), None) - self.assertEqual(req2.headers.get('Zyte-Client'), None) + self.assertEqual(req2.headers.get('Zyte-Client'), client) def test_scrapy_httpproxy_integration(self): self.spider.zyte_smartproxy_enabled = True