• info {Object}
      • httpVersion {string}
      • httpVersionMajor {integer}
      • httpVersionMinor {integer}
      • statusCode {integer}
      • statusMessage {string}
      • headers {Object}
      • rawHeaders {string[]}

    服务器发送 1xx 中间响应(不包括 101 Upgrade)时触发。 此事件的监听器将会接收一个对象,该对象包含 HTTP 版本,状态码,状态消息,键值对请求头对象、以及具有原始请求头名称和值的数组。

    1. const http = require('http');
    2. const options = {
    3. host: '127.0.0.1',
    4. port: 8080,
    5. path: '/length_request'
    6. };
    7. // 发出请求。
    8. const req = http.request(options);
    9. req.end();
    10. req.on('information', (info) => {
    11. console.log(`获得主响应之前的信息: ${info.statusCode}`);
    12. });

    101 Upgrade 状态不会触发此事件,因为它们与传统的 HTTP 请求/响应链断开,例如 Web 套接字、现场 TLS 升级、或 HTTP 2.0。 要收到 101 Upgrade 的通知,请改为监听 ['upgrade'] 事件。