當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。