feat(har): record serverIPAddress for API requests (#32660)
Discovered working on https://github.com/microsoft/playwright/pull/32658. We're recording the remote server address for browser requests, but not for API requests. This PR adds that for API requests.
This commit is contained in:
parent
7d4aa0aa8e
commit
825df6c074
|
|
@ -74,6 +74,8 @@ export type APIRequestFinishedEvent = {
|
|||
statusMessage: string;
|
||||
body?: Buffer;
|
||||
timings: har.Timings;
|
||||
serverIPAddress?: string;
|
||||
serverPort?: number;
|
||||
securityDetails?: har.SecurityDetails;
|
||||
};
|
||||
|
||||
|
|
@ -304,6 +306,8 @@ export abstract class APIRequestContext extends SdkObject {
|
|||
let tcpConnectionAt: number | undefined;
|
||||
let tlsHandshakeAt: number | undefined;
|
||||
let requestFinishAt: number | undefined;
|
||||
let serverIPAddress: string | undefined;
|
||||
let serverPort: number | undefined;
|
||||
|
||||
let securityDetails: har.SecurityDetails | undefined;
|
||||
|
||||
|
|
@ -332,6 +336,8 @@ export abstract class APIRequestContext extends SdkObject {
|
|||
cookies,
|
||||
body,
|
||||
timings,
|
||||
serverIPAddress,
|
||||
serverPort,
|
||||
securityDetails,
|
||||
};
|
||||
this.emit(APIRequestContext.Events.RequestFinished, requestFinishedEvent);
|
||||
|
|
@ -501,6 +507,9 @@ export abstract class APIRequestContext extends SdkObject {
|
|||
};
|
||||
}
|
||||
});
|
||||
|
||||
serverIPAddress = socket.remoteAddress;
|
||||
serverPort = socket.remotePort;
|
||||
});
|
||||
request.on('finish', () => { requestFinishAt = monotonicTime(); });
|
||||
|
||||
|
|
|
|||
|
|
@ -213,6 +213,11 @@ export class HarTracer {
|
|||
harEntry.response.httpVersion = event.httpVersion;
|
||||
harEntry.response.redirectURL = event.headers.location || '';
|
||||
|
||||
if (!this._options.omitServerIP) {
|
||||
harEntry.serverIPAddress = event.serverIPAddress;
|
||||
harEntry._serverPort = event.serverPort;
|
||||
}
|
||||
|
||||
if (!this._options.omitTiming) {
|
||||
harEntry.timings = event.timings;
|
||||
this._computeHarEntryTotalTime(harEntry);
|
||||
|
|
|
|||
|
|
@ -835,6 +835,9 @@ it('should include API request', async ({ contextFactory, server }, testInfo) =>
|
|||
ssl: expect.any(Number),
|
||||
wait: expect.any(Number),
|
||||
}));
|
||||
|
||||
expect(entry.serverIPAddress).toBeDefined();
|
||||
expect(entry._serverPort).toEqual(server.PORT);
|
||||
});
|
||||
|
||||
it('should respect minimal mode for API Requests', async ({ contextFactory, server }, testInfo) => {
|
||||
|
|
@ -848,6 +851,8 @@ it('should respect minimal mode for API Requests', async ({ contextFactory, serv
|
|||
expect(entries).toHaveLength(1);
|
||||
const [entry] = entries;
|
||||
expect(entry.timings).toEqual({ receive: -1, send: -1, wait: -1 });
|
||||
expect(entry.serverIPAddress).toBeUndefined();
|
||||
expect(entry._serverPort).toBeUndefined();
|
||||
expect(entry.request.cookies).toEqual([]);
|
||||
expect(entry.request.bodySize).toBe(-1);
|
||||
expect(entry.response.bodySize).toBe(-1);
|
||||
|
|
|
|||
Loading…
Reference in a new issue