阿西河

所有教程

公众号
🌙
阿西河前端的公众号

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js http2 消息头对象

      Node.js http2 消息头对象

      Headers are represented as own-properties on JavaScript objects. The property keys will be serialized to lower-case. Property values should be strings (if they are not they will be coerced to strings) or an Array of strings (in order to send more than one value per header field).

      const headers = {
        ':status': '200',
        'content-type': 'text-plain',
        'ABC': ['has', 'more', 'than', 'one', 'value']
      };
      

      stream.respond(headers); Header objects passed to callback functions will have a null prototype. This means that normal JavaScript object methods such as Object.prototype.toString() and Object.prototype.hasOwnProperty() will not work.

      For incoming headers:

      • The :status header is converted to number.
      • Duplicates of :status, :method, :authority, :scheme, :path, :protocol, age, authorization, access-control-allow-credentials, access-control-max-age, access-control-request-method, content-encoding, content-language, content-length, content-location, content-md5, content-range, content-type, date, dnt, etag, expires, from, if-match, if-modified-since, if-none-match, if-range, if-unmodified-since, last-modified, location, max-forwards, proxy-authorization, range, referer,retry-after, tk, upgrade-insecure-requests, user-agent or x-content-type-options are discarded.
      • set-cookie is always an array. Duplicates are added to the array.
      • For duplicate cookie headers, the values are joined together with ‘; ‘.
      • For all other headers, the values are joined together with ‘, ‘.
      const http2 = require('http2');
      const server = http2.createServer();
      server.on('stream', (stream, headers) => {
        console.log(headers[':path']);
        console.log(headers.ABC);
      });
      

      更多内容请参考:Node.js HTTP2,或者通过 点击对应菜单 进行查看;


      目录
      本文目录
      目录