File tree 2 files changed +11
-5
lines changed
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)
390
390
391
391
overrides : dict = {}
392
392
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 (
395
397
self .process_request_headers (
396
398
self .browser_type_name , playwright_request , scrapy_headers
397
399
)
398
400
)
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
402
405
403
406
if playwright_request .is_navigation_request ():
404
407
overrides ["method" ] = method
Original file line number Diff line number Diff line change @@ -82,7 +82,10 @@ async def test_use_playwright_headers(self):
82
82
headers = json .loads (resp .css ("pre::text" ).get ())
83
83
headers = {key .lower (): value for key , value in headers .items ()}
84
84
assert headers ["user-agent" ] == self .browser_type
85
+ assert req .headers ["user-agent" ].decode ("utf-8" ) == self .browser_type
85
86
assert "asdf" not in headers
87
+ assert "asdf" not in req .headers
88
+ assert b"asdf" not in req .headers
86
89
87
90
@pytest .mark .asyncio
88
91
async def test_use_playwright_headers_deprecated (self ):
You can’t perform that action at this time.
0 commit comments