-
Notifications
You must be signed in to change notification settings - Fork 4.9k
fix(routeFromHAR, take 2): hack harRouter to merge set-cookie headers #38487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Route.fulfill currently does not support multiple headers with the same name (microsoft#37342). There are workarounds when using this API directly (merging headers, tweaking the header name casing, etc.), but this is problematic for routeFromHAR, which depends on this API internally. This patch adds special handling for set-cookie headers within harRouter to merge them into one header. There's some precedent for treating set-cookie specially at various places in the codebase (ex: https://github.com/microsoft/playwright/blob/f54478a23e0daa450fe524905eabc8aabf6efb07/packages/playwright-core/src/utils/isomorphic/headers.ts#L29, https://github.com/microsoft/playwright/blob/baeb065e9ea84502f347129a0b896a85d2a8dada/packages/playwright-core/src/server/chromium/crNetworkManager.ts#L675), so I think this is okay.
| expect(await page2.evaluate(fetchFunction, { path: '/echo', body: '12' })).toBe('12'); | ||
| }); | ||
|
|
||
| it('should replay requests with multiple set-cookie headers properly', async ({ context, asset }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this test is still necessary with the multi-cookie test below (seems like that one both records and replays a HAR)
| expect(cookie2.split('; ').sort().join('; ')).toBe('first=foo'); | ||
| }); | ||
|
|
||
| it('should record multiple set-cookie headers', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from #38255 (comment)
Test results for "MCP"2688 passed, 116 skipped Merge workflow run. |
Test results for "tests 1"7 flaky39445 passed, 792 skipped Merge workflow run. |
This was previously closed in #38255 due to inactivity. This PR has been updated with the feedback from @yury-s on the previous PR to avoid a bug with single set-cookie headers.
Following PR description is copied from the original:
Route.fulfill currently does not support multiple headers with the same name (#37342). There are workarounds when using this API directly (merging headers, tweaking the header name casing, etc.), but this is problematic for routeFromHAR, which depends on
this API internally. This patch adds special handling for set-cookie headers within harRouter to merge them into one header. There's some precedent for treating set-cookie specially at various places in the codebase (ex:
playwright/packages/playwright-core/src/utils/isomorphic/headers.ts
Line 29 in f54478a
playwright/packages/playwright-core/src/server/chromium/crNetworkManager.ts
Line 675 in baeb065