fix(trace viewer): allow http/https mismatch when deployed as https (#21289)

References #21263.
This commit is contained in:
Dmitry Gozman 2023-02-28 17:08:46 -08:00 committed by GitHub
parent 933332ad97
commit b343d453bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -17,6 +17,7 @@
import type { SnapshotStorage } from './snapshotStorage';
import type { URLSearchParams } from 'url';
import type { SnapshotRenderer } from './snapshotRenderer';
import type { ResourceSnapshot } from '@trace/snapshot';
type Point = { x: number, y: number };
@ -62,10 +63,14 @@ export class SnapshotServer {
});
}
async serveResource(requestUrl: string, snapshotUrl: string): Promise<Response> {
async serveResource(requestUrlAlternatives: string[], snapshotUrl: string): Promise<Response> {
let resource: ResourceSnapshot | undefined;
const snapshot = this._snapshotIds.get(snapshotUrl)!;
const url = removeHash(requestUrl);
const resource = snapshot?.resourceByUrl(url);
for (const requestUrl of requestUrlAlternatives) {
resource = snapshot?.resourceByUrl(removeHash(requestUrl));
if (resource)
break;
}
if (!resource)
return new Response(null, { status: 404 });

View File

@ -124,7 +124,14 @@ async function doFetch(event: FetchEvent): Promise<Response> {
const { snapshotServer } = loadedTraces.get(traceUrl) || {};
if (!snapshotServer)
return new Response(null, { status: 404 });
return snapshotServer.serveResource(request.url, snapshotUrl);
const lookupUrls = [request.url];
// When trace viewer is deployed over https, Chrome changes http subresources
// in snapshots to https, presumably to avoid mixed-content.
// In this case, we additionally match http resources from the archive.
if (self.registration.scope.startsWith('https://') && request.url.startsWith('https://'))
lookupUrls.push(request.url.replace(/^https/, 'http'));
return snapshotServer.serveResource(lookupUrls, snapshotUrl);
}
async function gc() {