Skip to content

Commit dd03316

Browse files
Copilothi-ogawa
andauthored
fix(ui): detect gzip by magic numbers instead of Content-Type header in html reporter (#9278)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: hi-ogawa <4232207+hi-ogawa@users.noreply.github.com> Co-authored-by: Hiroshi Ogawa <hi.ogawa.zz@gmail.com>
1 parent c788829 commit dd03316

File tree

1 file changed

+8
-8
lines changed
  • packages/ui/client/composables/client

1 file changed

+8
-8
lines changed

packages/ui/client/composables/client/static.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ export function createStaticClient(): VitestClient {
9898

9999
async function registerMetadata() {
100100
const res = await fetch(window.METADATA_PATH!)
101-
const contentType = res.headers.get('content-type')?.toLowerCase() || ''
102-
if (
103-
contentType.includes('application/gzip')
104-
|| contentType.includes('application/x-gzip')
105-
) {
106-
const compressed = new Uint8Array(await res.arrayBuffer())
107-
const decompressed = strFromU8(decompressSync(compressed))
101+
const content = new Uint8Array(await res.arrayBuffer())
102+
103+
// Check for gzip magic numbers (0x1f 0x8b) to determine if content is compressed.
104+
// This handles cases where a static server incorrectly sets Content-Encoding: gzip
105+
// for .gz files, causing the browser to auto-decompress before we process the raw gzip data.
106+
if (content.length >= 2 && content[0] === 0x1F && content[1] === 0x8B) {
107+
const decompressed = strFromU8(decompressSync(content))
108108
metadata = parse(decompressed) as HTMLReportMetadata
109109
}
110110
else {
111-
metadata = parse(await res.text()) as HTMLReportMetadata
111+
metadata = parse(strFromU8(content)) as HTMLReportMetadata
112112
}
113113
const event = new Event('open')
114114
ctx.ws.dispatchEvent(event)

0 commit comments

Comments
 (0)