feat(web): inspect upstream responses from route handlers
Merged
RU
18d ago+122+122+012345678901234567890123456789-13-13-01234567890123456789
- Adds
route.fetch()toWebRoute: reads the upstream response inside a route handler without deciding the route, then the handler fulfills, continues, or aborts as usual. - Sends the request's own headers plus the configured site headers,
maxRedirects: 0so a redirect can't take the fetch past the navigation rule (packages/web/src/browser.ts). - Returns a
WebResponse(url,status,headers,text(),json()); the body is read through the sharedreadResponseBody, so an unreadable body keeps the metadata and rejectstext()/json()withACTION_FAILED.
await browser.route('**/api/user', async (route) => {
const upstream = await route.fetch();
const user = await upstream.json<User>();
await route.fulfill({ json: { ...user, plan: 'pro' } });
});
Verified
Ran it locally: yes
packages/web/tests/integration/routes.test.tsagainst real Chromium: fetch + amend + fulfill with site headers (server hit once), unreadable body keeps metadata, 302 returned without following. All 3 fail withmaxRedirects: 0removed and the body failure swallowed.- Full
packages/websuite: 599 passed.