未验证 提交 381b99f6 编写于 作者: A Alex Ross 提交者: GitHub

Also run the output based auto port forwarding (#114424)

Fixes microsoft/vscode-internalbacklog#1736
上级 f7e7a954
......@@ -5,7 +5,7 @@
import { Emitter, Event } from 'vs/base/common/event';
import { IDisposable } from 'vs/base/common/lifecycle';
import { isWindows } from 'vs/base/common/platform';
import { isWindows, OperatingSystem } from 'vs/base/common/platform';
import { URI } from 'vs/base/common/uri';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/platform/log/common/log';
......@@ -85,8 +85,12 @@ function getOtherLocalhost(host: string): string | undefined {
return (host === 'localhost') ? '127.0.0.1' : ((host === '127.0.0.1') ? 'localhost' : undefined);
}
export function isPortPrivileged(port: number): boolean {
return !isWindows && (port < 1024);
export function isPortPrivileged(port: number, os?: OperatingSystem): boolean {
if (os) {
return os !== OperatingSystem.Windows && (port < 1024);
} else {
return !isWindows && (port < 1024);
}
}
export abstract class AbstractTunnelService implements ITunnelService {
......
......@@ -212,10 +212,12 @@ export class AutomaticPortForwarding extends Disposable implements IWorkbenchCon
remoteAgentService.getEnvironment().then(environment => {
if (environment?.os === OperatingSystem.Windows) {
this._register(new WindowsAutomaticPortForwarding(terminalService, notificationService, openerService,
remoteExplorerService, configurationService, debugService, tunnelService));
this._register(new OutputAutomaticPortForwarding(terminalService, notificationService, openerService,
remoteExplorerService, configurationService, debugService, tunnelService, remoteAgentService, false));
} else if (environment?.os === OperatingSystem.Linux) {
this._register(new LinuxAutomaticPortForwarding(configurationService, remoteExplorerService, notificationService, openerService, tunnelService));
this._register(new ProcAutomaticPortForwarding(configurationService, remoteExplorerService, notificationService, openerService, tunnelService));
this._register(new OutputAutomaticPortForwarding(terminalService, notificationService, openerService,
remoteExplorerService, configurationService, debugService, tunnelService, remoteAgentService, true));
}
});
}
......@@ -355,7 +357,7 @@ class OnAutoForwardedAction extends Disposable {
}
}
class WindowsAutomaticPortForwarding extends Disposable {
class OutputAutomaticPortForwarding extends Disposable {
private portsFeatures?: IDisposable;
private urlFinder?: UrlFinder;
private notifier: OnAutoForwardedAction;
......@@ -368,7 +370,9 @@ class WindowsAutomaticPortForwarding extends Disposable {
private readonly remoteExplorerService: IRemoteExplorerService,
private readonly configurationService: IConfigurationService,
private readonly debugService: IDebugService,
readonly tunnelService: ITunnelService
readonly tunnelService: ITunnelService,
private readonly remoteAgentService: IRemoteAgentService,
readonly privilegedOnly: boolean
) {
super();
this.portsAttributes = new PortsAttributes(configurationService);
......@@ -408,6 +412,9 @@ class WindowsAutomaticPortForwarding extends Disposable {
if (this.portsAttributes.getAttributes(localUrl.port)?.onAutoForward === OnPortForward.Ignore) {
return;
}
if (this.privilegedOnly && !isPortPrivileged(localUrl.port, (await this.remoteAgentService.getEnvironment())?.os)) {
return;
}
const forwarded = await this.remoteExplorerService.forward(localUrl);
if (forwarded) {
this.notifier.doAction([forwarded]);
......@@ -423,7 +430,7 @@ class WindowsAutomaticPortForwarding extends Disposable {
}
}
class LinuxAutomaticPortForwarding extends Disposable {
class ProcAutomaticPortForwarding extends Disposable {
private candidateListener: IDisposable | undefined;
private autoForwarded: Set<string> = new Set();
private notifier: OnAutoForwardedAction;
......
......@@ -18,6 +18,7 @@ export class UrlFinder extends Disposable {
* http://0.0.0.0:4000 - Elixir Phoenix
*/
private static readonly localUrlRegex = /\b\w{2,20}:\/\/(?:localhost|127\.0\.0\.1|0\.0\.0\.0|:\d{2,5})[\w\-\.\~:\/\?\#[\]\@!\$&\(\)\*\+\,\;\=]*/gim;
private static readonly extractPortRegex = /(localhost|127\.0\.0\.1|0\.0\.0\.0):(\d{1,5})/;
/**
* https://github.com/microsoft/vscode-remote-release/issues/3949
*/
......@@ -106,7 +107,8 @@ export class UrlFinder extends Disposable {
const serverUrl = new URL(match);
if (serverUrl) {
// check if the port is a valid integer value
const port = parseFloat(serverUrl.port!);
const portMatch = match.match(UrlFinder.extractPortRegex);
const port = parseFloat(serverUrl.port ? serverUrl.port : (portMatch ? portMatch[2] : 'NaN'));
if (!isNaN(port) && Number.isInteger(port) && port > 0 && port <= 65535) {
// normalize the host name
let host = serverUrl.hostname;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册