148
149
export function extractLocalHostUriMetaDataForPortMapping(uri: URI): { address: string; port: number } | undefined {
150
>
if (uri.scheme !== 'http' && uri.scheme !== 'https') {
tunnel.ts
151
>
return undefined;
152
>
}
153
>
const localhostMatch = /^(localhost|127\.0\.0\.1|0\.0\.0\.0):(\d+)$/.exec(uri.authority);
154
>
if (!localhostMatch) {
155
>
return undefined;
156
>
}
157
>
return {
158
>
address: localhostMatch[1],
159
>
port: +localhostMatch[2],
160
>
};
161
>
}
162
163
export function extractQueryLocalHostUriMetaDataForPortMapping(uri: URI): { address: string; port: number } | undefined {
164
>
if (uri.scheme !== 'http' && uri.scheme !== 'https' || !uri.query) {
tunnel.ts
165
return undefined;
166
}
167
>
const keyvalues = uri.query.split('&');
tunnel.ts
168
>
for (const keyvalue of keyvalues) {
169
>
const value = keyvalue.split('=')[1];
170
>
if (/^https?:/.exec(value)) {
171
>
const result = extractLocalHostUriMetaDataForPortMapping(URI.parse(value));
172
>
if (result) {
173
>
return result;
174
>
}
175
>
}
176
>
}
177
return undefined;
178
}