fix(tracing): record available response headers without waiting for extra info (#23483)

Fixes #23115
This commit is contained in:
Yury Semikhatsky 2023-06-02 14:15:20 -07:00 committed by GitHub
parent dd3ca6907a
commit 401fc4cb9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -478,18 +478,26 @@ export class HarTracer {
this._addBarrier(page || request.serviceWorker(), request.rawRequestHeaders().then(headers => {
this._recordRequestHeadersAndCookies(harEntry, headers);
}));
// Record available headers including redirect location in case the tracing is stopped before
// reponse extra info is received (in Chromium).
this._recordResponseHeaders(harEntry, response.headers());
this._addBarrier(page || request.serviceWorker(), response.rawResponseHeaders().then(headers => {
if (!this._options.omitCookies) {
for (const header of headers.filter(header => header.name.toLowerCase() === 'set-cookie'))
harEntry.response.cookies.push(parseCookie(header.value));
}
harEntry.response.headers = headers;
const contentType = headers.find(header => header.name.toLowerCase() === 'content-type');
if (contentType)
harEntry.response.content.mimeType = contentType.value;
this._recordResponseHeaders(harEntry, headers);
}));
}
private _recordResponseHeaders(harEntry: har.Entry, headers: HeadersArray) {
if (!this._options.omitCookies) {
harEntry.response.cookies = headers
.filter(header => header.name.toLowerCase() === 'set-cookie')
.map(header => parseCookie(header.value));
}
harEntry.response.headers = headers;
const contentType = headers.find(header => header.name.toLowerCase() === 'content-type');
if (contentType)
harEntry.response.content.mimeType = contentType.value;
}
private _computeHarEntryTotalTime(harEntry: har.Entry) {
harEntry.time = [
harEntry.timings.dns,