How can I send multiple Set-Cookie headers from API Gateway using a proxied Lambda

后端 未结 5 1984
醉话见心
醉话见心 2021-01-17 09:40

I\'m using API Gateway\'s Proxy integration to call a Lambda. The output format specification is this follow JSON format:

{
  \"statusCode\": httpStatusCode,         


        
5条回答
  •  时光说笑
    2021-01-17 10:14

    Couple of years late, but I just required to implement something like this and this is how I was able to make it work:

    ...
    
    //15 minutes
    var expirationTime = new Date(new Date().getTime() + 15 * 60 * 1000);
    //30 minutes
    var expirationTime2 = new Date(new Date().getTime() + 30 * 60 * 1000);
    
    var response = {};
    
    var cookies = [];
    cookies.push("testCookie={'keyX':'valx', 'keyy':'valy'}; Expires=" + expirationTime + ";");
    cookies.push("testCookie2={'key1':'val1', 'key2':'val2'}; Expires=" + expirationTime2 + ";");
    
    response.headers["Set-Cookie"] =  cookies;
    
    ...
    

    Each array item will be processed independently, so you can add as many cookies to the array with different settings.

    i.e.

    cookies.push("testCookie3={'key1':'val1', 'key2':'val2'}; Expires=" + expirationTime2 + "; Max-Age=...");
    
    cookies.push("testCookie4={'key1':'val1', 'key2':'val2'}; Expires=" + expirationTime2 + "; Domain=; Path=");
    

提交回复
热议问题