阿西河

所有教程

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

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js http2 response.setHeader

      Node.js http2 response.setHeader

      新增于: v8.4.0

      • name < string>
      • value < string> | < string[]>

      Sets a single header value for implicit headers. If this header already exists in the to-be-sent headers, its value will be replaced. Use an array of strings here to send multiple headers with the same name.

      response.setHeader('Content-Type', 'text/html');
      

      or

      response.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']);
      

      Attempting to set a header field name or value that contains invalid characters will result in a TypeError being thrown.

      When headers have been set with response.setHeader(), they will be merged with any headers passed to response.writeHead(), with the headers passed to response.writeHead() given precedence.

      // returns content-type = text/plain
      const server = http2.createServer((req, res) => {
        res.setHeader('Content-Type', 'text/html');
        res.setHeader('X-Foo', 'bar');
        res.writeHead(200, { 'Content-Type': 'text/plain' });
        res.end('ok');
      });
      

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


      目录
      本文目录
      目录