UNPKG

@theia/core

Version:

Theia is a cloud & desktop IDE framework implemented in TypeScript.

83 lines • 3.37 kB
/******************************************************************************** * Copyright (C) 2022 TypeFox and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * This Source Code may also be made available under the following Secondary * Licenses when the conditions for such availability set forth in the Eclipse * Public License v. 2.0 are satisfied: GNU General Public License, version 2 * with the GNU Classpath Exception which is available at * https://www.gnu.org/software/classpath/license.html. * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 ********************************************************************************/ import { __decorate } from "tslib"; import { decorate, injectable, inject, named } from 'inversify'; import { NodeRequestService } from '@theia/request/lib/node-request-service'; import { ElectronSecurityToken } from '../../electron-common/electron-token.js'; import { ILogger } from '../../common/index.js'; decorate(injectable(), NodeRequestService); let ElectronBackendRequestService = class ElectronBackendRequestService extends NodeRequestService { async getProxyUrl(url) { if (this.proxyUrl) { return this.proxyUrl; } try { const proxy = await this.resolveProxy(url); if (proxy && proxy !== 'DIRECT') { const proxyHost = proxy.split(' ')[1]; return this.buildProxyUrl(url, proxyHost); } } catch (e) { this.logger.error('Could not resolve electron proxy.', e); } return super.getProxyUrl(url); } async resolveProxy(url) { // TODO: Implement IPC to the backend to access the Electron proxy resolver return undefined; } buildProxyUrl(url, proxyHost) { if (proxyHost.startsWith('http://') || proxyHost.startsWith('https://')) { return proxyHost; } if (url.startsWith('http://')) { return 'http://' + proxyHost; } else if (url.startsWith('https://')) { return 'https://' + proxyHost; } return proxyHost; } async processOptions(options) { options = await super.processOptions(options); const endpoint = new URL(options.url); if (endpoint.hostname === 'localhost') { const securityToken = process.env[ElectronSecurityToken]; if (securityToken) { let cookie = options.headers?.['Cookie'] ?? ''; if (cookie) { cookie += '; '; } cookie += `${ElectronSecurityToken}=${securityToken}`; options.headers = { ...(options.headers || {}), 'Cookie': cookie }; } } return options; } }; __decorate([ inject(ILogger), named('core:ElectronBackendRequestService') ], ElectronBackendRequestService.prototype, "logger", void 0); ElectronBackendRequestService = __decorate([ injectable() ], ElectronBackendRequestService); export { ElectronBackendRequestService }; //# sourceMappingURL=electron-backend-request-service.js.map