Skip to content

Commit

Permalink
change archive type detection to use content disposition (#248)
Browse files Browse the repository at this point in the history
fixes #246
  • Loading branch information
joaomoreno authored Nov 24, 2023
1 parent 7bd2c32 commit 62881f0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 26 deletions.
50 changes: 26 additions & 24 deletions lib/download.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,32 @@ describe('sane downloads', () => {
await fs.mkdir(testTempDir, { recursive: true });
});

for (const platform of platforms) {
test.concurrent(platform, async () => {
const location = await downloadAndUnzipVSCode({
platform,
version: 'stable',
cachePath: testTempDir,
reporter: new SilentReporter(),
for (const quality of ['insiders', 'stable']) {
for (const platform of platforms) {
test.concurrent(`${quality}/${platform}`, async () => {
const location = await downloadAndUnzipVSCode({
platform,
version: quality,
cachePath: testTempDir,
reporter: new SilentReporter(),
});

if (!existsSync(location)) {
throw new Error(`expected ${location} to exist for ${platform}`);
}

const exePath = resolveCliPathFromVSCodeExecutablePath(location, platform);
if (!existsSync(exePath)) {
throw new Error(`expected ${exePath} to from ${location}`);
}

if (platform === systemDefaultPlatform) {
const version = spawnSync(exePath, ['--version']);
expect(version.status).to.equal(0);
expect(version.stdout.toString().trim()).to.not.be.empty;
}
});

if (!existsSync(location)) {
throw new Error(`expected ${location} to exist for ${platform}`);
}

const exePath = resolveCliPathFromVSCodeExecutablePath(location, platform);
if (!existsSync(exePath)) {
throw new Error(`expected ${exePath} to from ${location}`);
}

if (platform === systemDefaultPlatform) {
const version = spawnSync(exePath, ['--version']);
expect(version.status).to.equal(0);
expect(version.stdout.toString().trim()).to.not.be.empty;
}
});
}
}

afterAll(async () => {
Expand All @@ -64,7 +66,7 @@ describe('sane downloads', () => {
});
});

describe('fetchTargetInferredVersion', () => {
describe.skip('fetchTargetInferredVersion', () => {
let stable: string[];
let insiders: string[];
let extensionsDevelopmentPath = join(tmpdir(), 'vscode-test-tmp-workspace');
Expand Down
19 changes: 17 additions & 2 deletions lib/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@ interface IDownload {
length: number;
}

function getFilename(contentDisposition: string) {
const parts = contentDisposition.split(';').map((s) => s.trim());

for (const part of parts) {
const match = /^filename="?([^"]*)"?$/i.exec(part);

if (match) {
return match[1];
}
}

return undefined;
}

/**
* Download a copy of VS Code archive to `.vscode-test`.
*
Expand Down Expand Up @@ -219,8 +233,9 @@ async function downloadVSCodeArchive(options: DownloadOptions): Promise<IDownloa

const download = await request.getStream(url, timeout);
const totalBytes = Number(download.headers['content-length']);
const contentType = download.headers['content-type'];
const isZip = contentType ? contentType === 'application/zip' : url.endsWith('.zip');
const contentDisposition = download.headers['content-disposition'];
const fileName = contentDisposition ? getFilename(contentDisposition) : undefined;
const isZip = fileName?.endsWith('zip') ?? url.endsWith('.zip');

const timeoutCtrl = new request.TimeoutController(timeout);
options.reporter?.report({
Expand Down

0 comments on commit 62881f0

Please sign in to comment.