Do not store body
This commit is contained in:
parent
d82e67839b
commit
a1c93d3186
|
|
@ -368,10 +368,6 @@ export class CRNetworkManager {
|
|||
|
||||
_createResponse(request: InterceptableRequest, responsePayload: Protocol.Network.Response, hasExtraInfo: boolean): network.Response {
|
||||
const getResponseBody = async () => {
|
||||
const fulfilledBody = request._route?._fulfilledBody;
|
||||
if (fulfilledBody)
|
||||
return fulfilledBody;
|
||||
|
||||
const contentLengthHeader = Object.entries(responsePayload.headers).find(header => header[0].toLowerCase() === 'content-length');
|
||||
const expectedLength = contentLengthHeader ? +contentLengthHeader[1] : undefined;
|
||||
|
||||
|
|
@ -380,6 +376,10 @@ export class CRNetworkManager {
|
|||
if (response.body || !expectedLength)
|
||||
return Buffer.from(response.body, response.base64Encoded ? 'base64' : 'utf8');
|
||||
|
||||
// Make sure no network requests sent while reading the body for fulfilled requests.
|
||||
if (request._route?._fulfilled)
|
||||
return Buffer.from('');
|
||||
|
||||
// For <link prefetch we are going to receive empty body with non-empty content-length expectation. Reach out for the actual content.
|
||||
const resource = await session.send('Network.loadNetworkResource', { url: request.request.url(), frameId: this._serviceWorker ? undefined : request.request.frame()!._id, options: { disableCache: false, includeCredentials: true } });
|
||||
const chunks: Buffer[] = [];
|
||||
|
|
@ -599,7 +599,7 @@ class RouteImpl implements network.RouteDelegate {
|
|||
private readonly _session: CRSession;
|
||||
private _interceptionId: string;
|
||||
_alreadyContinuedParams: Protocol.Fetch.continueRequestParameters | undefined;
|
||||
_fulfilledBody: Buffer | undefined;
|
||||
_fulfilled: boolean = false;
|
||||
|
||||
constructor(session: CRSession, interceptionId: string) {
|
||||
this._session = session;
|
||||
|
|
@ -620,8 +620,8 @@ class RouteImpl implements network.RouteDelegate {
|
|||
}
|
||||
|
||||
async fulfill(response: types.NormalizedFulfillResponse) {
|
||||
this._fulfilled = true;
|
||||
const body = response.isBase64 ? response.body : Buffer.from(response.body).toString('base64');
|
||||
this._fulfilledBody = Buffer.from(body, 'base64');
|
||||
|
||||
const responseHeaders = splitSetCookieHeader(response.headers);
|
||||
await catchDisallowedErrors(async () => {
|
||||
|
|
|
|||
|
|
@ -479,10 +479,8 @@ it('should not go to the network for fulfilled requests body', {
|
|||
const responsePromise = page.waitForResponse('**/one-style.css');
|
||||
await page.goto(server.PREFIX + '/one-style.html');
|
||||
const response = await responsePromise;
|
||||
const body = await response.text();
|
||||
// In webkit the response body is not available.
|
||||
if (browserName !== 'webkit')
|
||||
expect(body).toBe('Not Found! (mocked)');
|
||||
const body = await response.body();
|
||||
expect(body).toBeTruthy();
|
||||
expect(serverHit).toBe(false);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue