File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -156,13 +156,15 @@ def get_proxyauth(self, spider):
156156 return basic_auth_header (self .apikey , '' )
157157
158158 def process_request (self , request , spider ):
159+ from scrapy_zyte_smartproxy import __version__
159160 if self ._is_enabled_for_request (request ):
160161 self ._set_zyte_smartproxy_default_headers (request )
161162 request .meta ['proxy' ] = self .url
162163 request .meta ['download_timeout' ] = self .download_timeout
163164 request .headers ['Proxy-Authorization' ] = self ._proxyauth
164165 if self .job_id :
165166 request .headers ['X-Crawlera-Jobid' ] = self .job_id
167+ request .headers ['X-Crawlera-Client' ] = 'scrapy-zyte-smartproxy/%s' % __version__
166168 self .crawler .stats .inc_value ('zyte_smartproxy/request' )
167169 self .crawler .stats .inc_value ('zyte_smartproxy/request/method/%s' % request .method )
168170 else :
Original file line number Diff line number Diff line change 1515from scrapy .exceptions import ScrapyDeprecationWarning
1616from twisted .internet .error import ConnectionRefusedError , ConnectionDone
1717
18- from scrapy_zyte_smartproxy import ZyteSmartProxyMiddleware
18+ from scrapy_zyte_smartproxy import __version__ , ZyteSmartProxyMiddleware
1919from scrapy_zyte_smartproxy .utils import exp_backoff
2020
2121
@@ -897,3 +897,15 @@ def test_settings_dict(self):
897897 mw .process_request (req , self .spider )
898898 assert mw .process_request (req , self .spider ) is None
899899 self .assertEqual (req .headers ['X-Crawlera-Profile' ], b'desktop' )
900+
901+ def test_client_header (self ):
902+ self .spider .zyte_smartproxy_enabled = True
903+ crawler = self ._mock_crawler (self .spider , self .settings )
904+ mw = self .mwcls .from_crawler (crawler )
905+ mw .open_spider (self .spider )
906+ req = Request ('http://www.scrapytest.org' )
907+ self .assertEqual (mw .process_request (req , self .spider ), None )
908+ self .assertEqual (
909+ req .headers .get ('X-Crawlera-Client' ).decode ('utf-8' ),
910+ 'scrapy-zyte-smartproxy/%s' % __version__
911+ )
You can’t perform that action at this time.
0 commit comments