提交 10ae5b4b 编写于 作者: J Johannes Rieken

Revert "don't use XHR when having a proxy configured"

This reverts commit 406833f6.
上级 406833f6
...@@ -8,26 +8,14 @@ import { TPromise } from 'vs/base/common/winjs.base'; ...@@ -8,26 +8,14 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { IRequestOptions, IRequestContext, IRequestFunction } from 'vs/base/node/request'; import { IRequestOptions, IRequestContext, IRequestFunction } from 'vs/base/node/request';
import { Readable } from 'stream'; import { Readable } from 'stream';
import { RequestService as NodeRequestService } from 'vs/platform/request/node/requestService'; import { RequestService as NodeRequestService } from 'vs/platform/request/node/requestService';
import { IHTTPConfiguration } from 'vs/platform/request/node/request';
/** /**
* This service exposes the `request` API, while using the global * This service exposes the `request` API, while using the global
* or configured proxy settings. * or configured proxy settings.
*/ */
export class RequestService extends NodeRequestService { export class RequestService extends NodeRequestService {
private _useXhrRequest = true;
protected configure(config: IHTTPConfiguration) {
this._useXhrRequest = !config.http.proxy;
}
request(options: IRequestOptions): TPromise<IRequestContext> { request(options: IRequestOptions): TPromise<IRequestContext> {
if (this._useXhrRequest) { return super.request(options, xhrRequest);
return super.request(options, xhrRequest);
} else {
return super.request(options);
}
} }
} }
...@@ -83,18 +71,13 @@ export const xhrRequest: IRequestFunction = (options: IRequestOptions): TPromise ...@@ -83,18 +71,13 @@ export const xhrRequest: IRequestFunction = (options: IRequestOptions): TPromise
}); });
}; };
// --- header utils
const unsafeHeaders = Object.create(null);
unsafeHeaders['User-Agent'] = true;
unsafeHeaders['Content-Length'] = true;
unsafeHeaders['Accept-Encoding'] = true;
function setRequestHeaders(xhr: XMLHttpRequest, options: IRequestOptions): void { function setRequestHeaders(xhr: XMLHttpRequest, options: IRequestOptions): void {
if (options.headers) { if (options.headers) {
for (let k in options.headers) { for (let k in options.headers) {
if (!unsafeHeaders[k]) { try {
xhr.setRequestHeader(k, options.headers[k]); xhr.setRequestHeader(k, options.headers[k]);
} catch (e) {
console.warn(e);
} }
} }
} }
......
...@@ -36,7 +36,7 @@ export class RequestService implements IRequestService { ...@@ -36,7 +36,7 @@ export class RequestService implements IRequestService {
this.configure(e.config); this.configure(e.config);
} }
protected configure(config: IHTTPConfiguration) { private configure(config: IHTTPConfiguration) {
this.proxyUrl = config.http && config.http.proxy; this.proxyUrl = config.http && config.http.proxy;
this.strictSSL = config.http && config.http.proxyStrictSSL; this.strictSSL = config.http && config.http.proxyStrictSSL;
this.authorization = config.http && config.http.proxyAuthorization; this.authorization = config.http && config.http.proxyAuthorization;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册