Skip to content

Commit

Permalink
Fix extension loading when server sends content-encoding: gzip header
Browse files Browse the repository at this point in the history
  • Loading branch information
samwillis committed Jul 24, 2024
1 parent 9519831 commit 6dcf4a3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/pglite/src/extensionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ export async function loadExtensionBundle(
const response = await fetch(bundlePath.toString());
if (!response.ok || !response.body) {
return null;
} else if (response.headers.get('Content-Encoding') === 'gzip') {
// Although the bundle is manually compressed, some servers will recognize
// that and add a content-encoding header. Fetch will then automatically
// decompress the response.
return response.blob();
} else {
const decompressionStream = new DecompressionStream("gzip");
const decompressedStream = new Response(
response.body.pipeThrough(decompressionStream),
);
return decompressedStream.blob();
}
const decompressionStream = new DecompressionStream("gzip");
const decompressedStream = new Response(
response.body.pipeThrough(decompressionStream),
);
return decompressedStream.blob();
}
}

Expand Down

0 comments on commit 6dcf4a3

Please sign in to comment.