File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -390,15 +390,18 @@ async def _request_handler(route: Route, playwright_request: PlaywrightRequest)
390390
391391 overrides : dict = {}
392392
393- if self .process_request_headers is not None :
394- overrides ["headers" ] = await _maybe_await (
393+ if self .process_request_headers is None :
394+ final_headers = await playwright_request .all_headers ()
395+ else :
396+ overrides ["headers" ] = final_headers = await _maybe_await (
395397 self .process_request_headers (
396398 self .browser_type_name , playwright_request , scrapy_headers
397399 )
398400 )
399- # the request that reaches the callback should contain the final headers
400- scrapy_headers .clear ()
401- scrapy_headers .update (overrides ["headers" ])
401+ # the request that reaches the callback should contain the final headers
402+ scrapy_headers .clear ()
403+ scrapy_headers .update (final_headers )
404+ del final_headers
402405
403406 if playwright_request .is_navigation_request ():
404407 overrides ["method" ] = method
Original file line number Diff line number Diff line change @@ -82,7 +82,10 @@ async def test_use_playwright_headers(self):
8282 headers = json .loads (resp .css ("pre::text" ).get ())
8383 headers = {key .lower (): value for key , value in headers .items ()}
8484 assert headers ["user-agent" ] == self .browser_type
85+ assert req .headers ["user-agent" ].decode ("utf-8" ) == self .browser_type
8586 assert "asdf" not in headers
87+ assert "asdf" not in req .headers
88+ assert b"asdf" not in req .headers
8689
8790 @pytest .mark .asyncio
8891 async def test_use_playwright_headers_deprecated (self ):
You can’t perform that action at this time.
0 commit comments