当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript IncomingMessage.setEncoding方法代码示例

本文整理汇总了TypeScript中http.IncomingMessage.setEncoding方法的典型用法代码示例。如果您正苦于以下问题:TypeScript IncomingMessage.setEncoding方法的具体用法?TypeScript IncomingMessage.setEncoding怎么用?TypeScript IncomingMessage.setEncoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在http.IncomingMessage的用法示例。


在下文中一共展示了IncomingMessage.setEncoding方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1:

 http.get(url, (response: IncomingMessage) => {
     response.setEncoding("utf8");
     response.on("data", (result: string) => {
         result.split("\n").forEach((char: string) => {
             console.log(char);
         });
     });
 });
开发者ID:kyanro,项目名称:nodeschool-learnyounode,代码行数:8,代码来源:main.ts

示例2: outputIfFinished

 http.get(url, (response: IncomingMessage) => {
     let buf: string = "";
     response.setEncoding("utf8");
     response.on("data", (result: string) => {
         buf += result;
     });
     response.on("end", () => {
         outputIfFinished(buf, index);
     });
 });
开发者ID:kyanro,项目名称:nodeschool-learnyounode,代码行数:10,代码来源:main.ts

示例3: _handler

	private _handler(request: IncomingMessage, response: ServerResponse) {
		if (request.method === 'GET') {
			if (/\.js(?:$|\?)/.test(request.url)) {
				this._handleFile(request, response, this.instrument);
			}
			else {
				this._handleFile(request, response);
			}
		}
		else if (request.method === 'HEAD') {
			this._handleFile(request, response, false, true);
		}
		else if (request.method === 'POST') {
			request.setEncoding('utf8');

			let data = '';
			request.on('data', function (chunk) {
				data += chunk;
			});

			request.on('end', () => {
				try {
					let rawMessages: any = JSON.parse(data);

					if (!Array.isArray(rawMessages)) {
						rawMessages = [rawMessages];
					}

					const messages: Message[] = rawMessages.map(function (messageString: string) {
						return JSON.parse(messageString);
					});

					Promise.all(messages.map(message => this._handleMessage(message))).then(
						() => {
							response.statusCode = 204;
							response.end();
						},
						() => {
							response.statusCode = 500;
							response.end();
						}
					);
				}
				catch (error) {
					response.statusCode = 500;
					response.end();
				}
			});
		}
		else {
			response.statusCode = 501;
			response.end();
		}
	}
开发者ID:bryanforbes,项目名称:intern,代码行数:54,代码来源:Server.ts

示例4:

	}, (res: IncomingMessage) => {

		res.setEncoding("utf8");

		let data = "";
		res.on("data", (chunk: string) => {
			data += chunk;
		}).on("end", () => {
			console.log(data);
		});

	});
开发者ID:Psychopoulet,项目名称:node-logs,代码行数:12,代码来源:compilation.ts

示例5: extractChannelTitle

		let request: ClientRequest = http.get(liveUrl, (res: IncomingMessage) => {
			let url: string = channel.url;
			let body: string = "";
			res.setEncoding("utf8");
			res.on("data", (chunk: string) => {
				body += chunk;
			});
			res.on("error", (error: any) => {
				console.log(`Conection Error : ${error.message}`);
			});
			res.on("end", () => {
				let title: string = extractChannelTitle(body);
				let broadcasting: boolean = checkBroadcasting(body);
				if (broadcasting) {
					if (lastChannelBroadcastings[url] === undefined ||
						lastChannelBroadcastings[url] === false) {
						lastChannelBroadcastings[url] = true;
						notifier.notify({
							title: title,
							message: url,
							icon: __dirname + "/../browser/notification.png",
							sound: true,
							wait: true,
						});
						notifier.on("click", (notifierObject: NodeNotifier, options: Notification) => {
							electron.shell.openExternal(options.message + '/live');
						});
					}
				} else {
					lastChannelBroadcastings[url] = false;
				}
				updateTrayIcon();
				if (mainWindow !== undefined) {
					mainWindow.webContents.send("updateChannelStatus", JSON.stringify({
						url: url,
						title: title,
						broadcasting: broadcasting,
					}));
				}
			});
		});
开发者ID:data9824,项目名称:SavannaAlert,代码行数:41,代码来源:main.ts

示例6:

    // test public props
    const maxHeadersCount: number = server.maxHeadersCount;
    const timeout: number = server.timeout;
    const listening: boolean = server.listening;
    const keepAliveTimeout: number = server.keepAliveTimeout;
    server.setTimeout().setTimeout(1000).setTimeout(() => {}).setTimeout(100, () => {});
}

// http IncomingMessage
// http ServerResponse
{
    // incoming
    const incoming: http.IncomingMessage = new http.IncomingMessage(new net.Socket());

    incoming.setEncoding('utf8');

    // stream
    incoming.pause();
    incoming.resume();

    // response
    const res: http.ServerResponse = new http.ServerResponse(incoming);

    // test headers
    res.setHeader('Content-Type', 'text/plain');
    const bool: boolean = res.hasHeader('Content-Type');
    const headers: string[] = res.getHeaderNames();

    // trailers
    res.addTrailers([
开发者ID:SaschaNaz,项目名称:DefinitelyTyped,代码行数:30,代码来源:http.ts


注:本文中的http.IncomingMessage.setEncoding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。