如何使用Azure Functions设置多个cookie?

时间:2018-11-09 16:41:32

标签: node.js cookies azure-functions

使用Azure Functions设置标头时,将传递一个标头为headerName且值为标头值的对象。

但是,在创建cookie时,每个cookie都需要其自己的“ Set-Cookie”头,但是Object键必须是唯一的。应该如何处理?

例如下面将两个对象键设置为“ Set-Cookie”;我的IDE不会被炸掉。

context.res = {
          status: 200,
          headers: {
              "Content-Type": "text/html",
              "Set-Cookie": "a=b; Secure; httpOnly; Path=/",
              "Set-Cookie": "b=c="; Secure; httpOnly; Path=/",
              "Cache-Control": "no-cache, no-store"
          },
          body:
              '<HTML><BODY>RESPONSE</BODY></HTML>'
      };
context.done();

1 个答案:

答案 0 :(得分:2)

不幸的是,这是当前的错误(首先出现in this issue)。这不是理想的方法,但是这是您现在可以使用的解决方法(请注意“ Set-Cookie”中的其他空白):

context.res = {
      status: 200,
      headers: {
          "Content-Type": "text/html",
          "Set-Cookie": "a=b; Secure; httpOnly; Path=/",
          "Set-Cookie ": "b=c="; Secure; httpOnly; Path=/",
          "Cache-Control": "no-cache, no-store"
      },
      body:
          '<HTML><BODY>RESPONSE</BODY></HTML>'
  };
context.done();
相关问题