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 {
|
_createResponse(request: InterceptableRequest, responsePayload: Protocol.Network.Response, hasExtraInfo: boolean): network.Response {
|
||||||
const getResponseBody = async () => {
|
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 contentLengthHeader = Object.entries(responsePayload.headers).find(header => header[0].toLowerCase() === 'content-length');
|
||||||
const expectedLength = contentLengthHeader ? +contentLengthHeader[1] : undefined;
|
const expectedLength = contentLengthHeader ? +contentLengthHeader[1] : undefined;
|
||||||
|
|
||||||
|
|
@ -380,6 +376,10 @@ export class CRNetworkManager {
|
||||||
if (response.body || !expectedLength)
|
if (response.body || !expectedLength)
|
||||||
return Buffer.from(response.body, response.base64Encoded ? 'base64' : 'utf8');
|
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.
|
// 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 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[] = [];
|
const chunks: Buffer[] = [];
|
||||||
|
|
@ -599,7 +599,7 @@ class RouteImpl implements network.RouteDelegate {
|
||||||
private readonly _session: CRSession;
|
private readonly _session: CRSession;
|
||||||
private _interceptionId: string;
|
private _interceptionId: string;
|
||||||
_alreadyContinuedParams: Protocol.Fetch.continueRequestParameters | undefined;
|
_alreadyContinuedParams: Protocol.Fetch.continueRequestParameters | undefined;
|
||||||
_fulfilledBody: Buffer | undefined;
|
_fulfilled: boolean = false;
|
||||||
|
|
||||||
constructor(session: CRSession, interceptionId: string) {
|
constructor(session: CRSession, interceptionId: string) {
|
||||||
this._session = session;
|
this._session = session;
|
||||||
|
|
@ -620,8 +620,8 @@ class RouteImpl implements network.RouteDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fulfill(response: types.NormalizedFulfillResponse) {
|
async fulfill(response: types.NormalizedFulfillResponse) {
|
||||||
|
this._fulfilled = true;
|
||||||
const body = response.isBase64 ? response.body : Buffer.from(response.body).toString('base64');
|
const body = response.isBase64 ? response.body : Buffer.from(response.body).toString('base64');
|
||||||
this._fulfilledBody = Buffer.from(body, 'base64');
|
|
||||||
|
|
||||||
const responseHeaders = splitSetCookieHeader(response.headers);
|
const responseHeaders = splitSetCookieHeader(response.headers);
|
||||||
await catchDisallowedErrors(async () => {
|
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');
|
const responsePromise = page.waitForResponse('**/one-style.css');
|
||||||
await page.goto(server.PREFIX + '/one-style.html');
|
await page.goto(server.PREFIX + '/one-style.html');
|
||||||
const response = await responsePromise;
|
const response = await responsePromise;
|
||||||
const body = await response.text();
|
const body = await response.body();
|
||||||
// In webkit the response body is not available.
|
expect(body).toBeTruthy();
|
||||||
if (browserName !== 'webkit')
|
|
||||||
expect(body).toBe('Not Found! (mocked)');
|
|
||||||
expect(serverHit).toBe(false);
|
expect(serverHit).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue