remoteAuthorityResolverService.ts 1.8 KB
Newer Older
A
Alex Dima 已提交
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

6
import { ResolvedAuthority, IRemoteAuthorityResolverService, ResolverResult } from 'vs/platform/remote/common/remoteAuthorityResolver';
7
import { RemoteAuthorities } from 'vs/base/common/network';
8
import { URI } from 'vs/base/common/uri';
A
Alex Dima 已提交
9 10 11

export class RemoteAuthorityResolverService implements IRemoteAuthorityResolverService {

12
	declare readonly _serviceBrand: undefined;
A
Alex Dima 已提交
13
	private readonly _cache: Map<string, ResolverResult>;
A
Alex Dima 已提交
14

A
Alex Dima 已提交
15
	constructor(
16
		resourceUriProvider: ((uri: URI) => URI) | undefined
A
Alex Dima 已提交
17
	) {
A
Alex Dima 已提交
18
		this._cache = new Map<string, ResolverResult>();
A
Alex Dima 已提交
19 20 21
		if (resourceUriProvider) {
			RemoteAuthorities.setDelegate(resourceUriProvider);
		}
A
Alex Dima 已提交
22 23
	}

A
Alex Dima 已提交
24 25 26 27 28
	async resolveAuthority(authority: string): Promise<ResolverResult> {
		if (!this._cache.has(authority)) {
			const result = this._doResolveAuthority(authority);
			RemoteAuthorities.set(authority, result.authority.host, result.authority.port);
			this._cache.set(authority, result);
A
Alex Dima 已提交
29
		}
A
Alex Dima 已提交
30
		return this._cache.get(authority)!;
31 32
	}

A
Alex Dima 已提交
33 34 35 36 37 38
	private _doResolveAuthority(authority: string): ResolverResult {
		if (authority.indexOf(':') >= 0) {
			const pieces = authority.split(':');
			return { authority: { authority, host: pieces[0], port: parseInt(pieces[1], 10) } };
		}
		return { authority: { authority, host: authority, port: 80 } };
A
Alex Dima 已提交
39 40
	}

A
Alex Dima 已提交
41 42 43
	clearResolvedAuthority(authority: string): void {
	}

A
Alex Dima 已提交
44 45 46 47 48 49
	setResolvedAuthority(resolvedAuthority: ResolvedAuthority) {
	}

	setResolvedAuthorityError(authority: string, err: any): void {
	}
}