當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript request.request函數代碼示例

本文整理匯總了TypeScript中vs/base/node/request.request函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript request函數的具體用法?TypeScript request怎麽用?TypeScript request使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了request函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: xhr

export function xhr(options: IXHROptions): TPromise<IXHRResponse> {
	const agent = getProxyAgent(options.url, { proxyUrl, strictSSL });
	options = assign({}, options);
	options = assign(options, { agent, strictSSL });

	return request(options).then(result => new TPromise<IXHRResponse>((c, e, p) => {
		const res = result.res;
		let stream: Stream = res;

		if (res.headers['content-encoding'] === 'gzip') {
			stream = stream.pipe(createGunzip());
		}

		const data: string[] = [];
		stream.on('data', c => data.push(c));
		stream.on('end', () => {
			const status = res.statusCode;

			if (options.followRedirects > 0 && (status >= 300 && status <= 303 || status === 307)) {
				let location = res.headers['location'];
				if (location) {
					let newOptions = {
						type: options.type, url: location, user: options.user, password: options.password, responseType: options.responseType, headers: options.headers,
						timeout: options.timeout, followRedirects: options.followRedirects - 1, data: options.data
					};
					xhr(newOptions).done(c, e, p);
					return;
				}
			}

			const response: IXHRResponse = {
				responseText: data.join(''),
				status,
				getResponseHeader: header => res.headers[header],
				readyState: 4
			};

			if ((status >= 200 && status < 300) || status === 1223) {
				c(response);
			} else {
				e(response);
			}
		});
	}, err => {
		let message: string;

		if (agent) {
			message = 'Unable to to connect to ' + options.url + ' through a proxy . Error: ' + err.message;
		} else {
			message = 'Unable to to connect to ' + options.url + '. Error: ' + err.message;
		}

		return TPromise.wrapError<IXHRResponse>({
			responseText: message,
			status: 404
		});
	}));
}
開發者ID:1833183060,項目名稱:vscode,代碼行數:58,代碼來源:rawHttpService.ts

示例2: test

	test('all colors documented', async function () {
		const reqContext = await request({ url: 'https://raw.githubusercontent.com/Microsoft/vscode-docs/vnext/docs/getstarted/theme-color-reference.md' }, CancellationToken.None);
		const content = await asText(reqContext);

		const expression = /\-\s*\`([\w\.]+)\`: (.*)/g;

		let m: RegExpExecArray;
		let colorsInDoc: { [id: string]: ColorInfo } = Object.create(null);
		while (m = expression.exec(content)) {
			colorsInDoc[m[1]] = { description: m[2], offset: m.index, length: m.length };
		}
		let missing = Object.create(null);
		let descriptionDiffs: { [id: string]: DescriptionDiff } = Object.create(null);

		let themingRegistry = Registry.as<IColorRegistry>(Extensions.ColorContribution);
		for (let color of themingRegistry.getColors()) {
			if (!colorsInDoc[color.id]) {
				if (!color.deprecationMessage) {
					missing[color.id] = getDescription(color);
				}
			} else {
				let docDescription = colorsInDoc[color.id].description;
				let specDescription = getDescription(color);
				if (docDescription !== specDescription) {
					descriptionDiffs[color.id] = { docDescription, specDescription };
				}
				delete colorsInDoc[color.id];
			}
		}
		let colorsInExtensions = await getColorsFromExtension();
		for (let colorId in colorsInExtensions) {
			if (!colorsInDoc[colorId]) {
				missing[colorId] = colorsInExtensions[colorId];
			} else {
				delete colorsInDoc[colorId];
			}
		}
		for (let colorId of experimental) {
			if (missing[colorId]) {
				delete missing[colorId];
			}
			if (colorsInDoc[colorId]) {
				assert.fail(`Color ${colorId} found in doc but marked experimental. Please remove from experimental list.`);
			}
		}

		let undocumentedKeys = Object.keys(missing).map(k => `${k}: ${missing[k]}`);
		assert.deepEqual(undocumentedKeys, [], 'Undocumented colors ids');

		let superfluousKeys = Object.keys(colorsInDoc);
		assert.deepEqual(superfluousKeys, [], 'Colors ids in doc that do not exist');

	});
開發者ID:KTXSoftware,項目名稱:KodeStudio,代碼行數:53,代碼來源:colorRegistry.releaseTest.ts

示例3: xhr

export function xhr(options: IXHROptions): TPromise<IXHRResponse> {
	let endpoint = parseUrl(options.url);
	options = assign({}, options);
	options = assign(options, { agent: getProxyAgent(endpoint) });

	return request(options).then(result => new TPromise<IXHRResponse>((c, e, p) => {
		let res = result.res;
		let data: string[] = [];
		res.on('data', c => data.push(c));
		res.on('end', () => {
			if (options.followRedirects > 0 && (res.statusCode >= 300 && res.statusCode <= 303 || res.statusCode === 307)) {
				let location = res.headers['location'];
				if (location) {
					let newOptions = {
						type: options.type, url: location, user: options.user, password: options.password, responseType: options.responseType, headers: options.headers,
						timeout: options.timeout, followRedirects: options.followRedirects - 1, data: options.data
					};
					xhr(newOptions).done(c, e, p);
					return;
				}
			}

			let response: IXHRResponse = {
				responseText: data.join(''),
				status: res.statusCode
			};

			if ((res.statusCode >= 200 && res.statusCode < 300) || res.statusCode === 1223) {
				c(response);
			} else {
				e(response);
			}
		});
	}, err => {
		let endpoint = parseUrl(options.url);
		let agent = getProxyAgent(endpoint);
		let message: string;

		if (agent) {
			message = 'Unable to to connect to ' + options.url + ' through proxy ' + getProxyURI(endpoint) + '. Error: ' + err.message;
		} else {
			message = 'Unable to to connect to ' + options.url + '. Error: ' + err.message;
		}

		return TPromise.wrapError<IXHRResponse>({
			responseText: message,
			status: 404
		});
	}));
}
開發者ID:gaoxiaojun,項目名稱:vscode,代碼行數:50,代碼來源:rawHttpService.ts

示例4: request

		return super.request(options, options => request(assign({}, options || {}, { getRawRequest })));
開發者ID:AlexxNica,項目名稱:sqlopsstudio,代碼行數:1,代碼來源:requestService.ts


注:本文中的vs/base/node/request.request函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。