Node.js http.ClientRequest.writableFinished API
http.ClientRequest.writableFinished是 http 模块中ClientRequest类的内置应用程序编程接口,用于检查所有数据是否已刷新。
句法:
const request.writableEnded
参数:此 API 不接受任何参数作为参数。
返回值:当且仅当所有数据都已刷新时,此方法才返回true 。
示例 1:
index.js
// NodeJS program to demonstrate the
// request.writableFinished APi
// Importing http module
const http = require('http');
// Create an HTTP server
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('okay');
});
// Now that server is running
server.listen(3000, '127.0.0.1', () => {
// make a request
const options = {
port: 3000,
host: '127.0.0.1',
headers: {
'Connection': 'Upgrade',
'Upgrade': 'websocket'
}
};
// getting client request
const req = http.request(options);
// checking if the all data has been flushed
// by using writableFinished api
if(req.writableFinished)
console.log('all data has been flushed')
else
console.log('all data has not been flushed')
process.exit(0)
});
输出: