Skip to content

Commit

Permalink
Use Zyte-Client (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gallaecio authored Feb 2, 2024
1 parent 4d7495e commit e43f5a2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions scrapy_zyte_smartproxy/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e43f5a2

Please sign in to comment.