本文整理汇总了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);
});
});
});
示例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);
});
});
示例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();
}
}
示例4:
}, (res: IncomingMessage) => {
res.setEncoding("utf8");
let data = "";
res.on("data", (chunk: string) => {
data += chunk;
}).on("end", () => {
console.log(data);
});
});
示例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,
}));
}
});
});
示例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([