Skip to content

Commit 35f22b3

Browse files
authored
Merge pull request #313 from soiamsoNG/MirrorSupport
Mirror support
2 parents 93e7b58 + 739a6a7 commit 35f22b3

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@
146146
"default": "haskell-language-server",
147147
"description": "Which language server to use."
148148
},
149+
"haskell.languageServerReleasesPath": {
150+
"scope": "resource",
151+
"type": "string",
152+
"default": "",
153+
"description": "An optional path to override where to check for haskell-language-server releases"
154+
},
149155
"haskell.serverExecutablePath": {
150156
"scope": "resource",
151157
"type": "string",
@@ -229,4 +235,4 @@
229235
"vscode-languageclient": "6.1.3",
230236
"yauzl": "^2.10.0"
231237
}
232-
}
238+
}

src/hlsBinaries.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as fs from 'fs';
33
import * as https from 'https';
44
import * as os from 'os';
55
import * as path from 'path';
6+
import * as url from 'url';
67
import { promisify } from 'util';
78
import { env, ExtensionContext, ProgressLocation, Uri, window, workspace, WorkspaceFolder } from 'vscode';
89
import { downloadFile, executableExists, httpsGetSilently } from './utils';
@@ -160,10 +161,18 @@ async function getProjectGhcVersion(context: ExtensionContext, dir: string, rele
160161
}
161162

162163
async function getLatestReleaseMetadata(context: ExtensionContext): Promise<IRelease | null> {
163-
const opts: https.RequestOptions = {
164-
host: 'api.github.com',
165-
path: '/repos/haskell/haskell-language-server/releases',
166-
};
164+
const releasesUrl = workspace.getConfiguration('haskell').languageServerReleasesPath
165+
? url.parse(workspace.getConfiguration('haskell').languageServerReleasesPath)
166+
: undefined;
167+
const opts: https.RequestOptions = releasesUrl
168+
? {
169+
host: releasesUrl.host,
170+
path: releasesUrl.path,
171+
}
172+
: {
173+
host: 'api.github.com',
174+
path: '/repos/haskell/haskell-language-server/releases',
175+
};
167176

168177
const offlineCache = path.join(context.globalStoragePath, 'latestApprovedRelease.cache.json');
169178

src/utils.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,25 @@ export async function httpsGetSilently(options: https.RequestOptions): Promise<s
4141
let data: string = '';
4242
https
4343
.get(opts, (res) => {
44-
res.on('data', (d) => (data += d));
45-
res.on('error', reject);
46-
res.on('close', () => {
47-
resolve(data);
48-
});
44+
if (res.statusCode === 301 || res.statusCode === 302) {
45+
if (!res.headers.location) {
46+
console.error('301/302 without a location header');
47+
return;
48+
}
49+
https.get(res.headers.location, (resAfterRedirect) => {
50+
resAfterRedirect.on('data', (d) => (data += d));
51+
resAfterRedirect.on('error', reject);
52+
resAfterRedirect.on('close', () => {
53+
resolve(data);
54+
});
55+
});
56+
} else {
57+
res.on('data', (d) => (data += d));
58+
res.on('error', reject);
59+
res.on('close', () => {
60+
resolve(data);
61+
});
62+
}
4963
})
5064
.on('error', reject);
5165
});

0 commit comments

Comments
 (0)