[Question][Bug] How can i add Header on specific routes ?
See original GitHub issueI want to add custom header like "X-E2E-USER": "fake-user@e2e.com"
on header only for specific route (ie: i want to add header for request on my API)
I found this in the doc https://playwright.dev/docs/api/class-route#route-continue that say i can overrides headers.
I try this but it’s doesn’t work. Headers are not overrides.
await page.route(/\/api\//i, async (route, request) => {
// Override headers
const existingHeaders = await request.allHeaders();
const headers = {
...existingHeaders,
"X-E2E-USER": "fake-user@e2e.com",
};
route.continue({ headers });
});
Maybe i miss something, but it’s not explain in the docs, maybe forget ?
I don’t want to use setExtraHTTPHeaders
because it’s override all http call, and i don’t want change all my request
await page.setExtraHTTPHeaders({ "X-E2E-USER": "fake-user@e2e.com" });
Issue Analytics
- State:
- Created a year ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
React Router: Create header for specific routes - Stack Overflow
I think the best way to do that is to add a Route for each header and pass an array of paths to...
Read more >Route traffic based on a custom HTTP header using an ...
Select your HTTP listener, and then choose View/edit rules. Choose the Add rules icon (the plus sign), and then choose Insert rule. Choose...
Read more >Injecting custom headers to http route - Discuss Istio
The headers field can accept only one value of type Headers. How is it possible to add more than one custome header? apiVersion:...
Read more >Appending and Removing Request/Response Headers
Appending and Removing Request/Response Headers. Gloo Edge can add and remove headers to/from requests and responses. We refer to this feature as “Header...
Read more >RFC 7230: Hypertext Transfer Protocol (HTTP/1.1)
RFC 7230 HTTP/1.1 Message Syntax and Routing June 2014 ought to be reflected in ... URI, and protocol version (Section 3.1.1), followed by...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@aslushnikov yes
before
is the part is missing for understanding this behavior ^^Indeed all the mock is working, it’s just the
how
i check that isn’t good.Actually my test is good, i get indeed my custom header so i close this issue
Thanks for your answer 😃
@Horsty80 the
page.on('request')
event happens before the route handler, so you get headers there before you modify them inpage.route
.