1
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Lambdaで複数値を持ったヘッダーを返す方法

Posted at

#はじめに
Lambda+S3でWebアプリを作った際にLambdaからSet-Cookieで複数のCookieを同時に設定したかったのですが、ちょっとハマったのでメモがてらここに残しておきます。
#環境

  • Node.js 10.X
  • Lambdaプロキシ統合利用
  • メソッドはGET

#コード
multiValueHeadersで設定できます。valueを配列にすれば良いだけみたいですね。ちなみに僕はJSONをJSON.stringifyして1時間くらいハマりました。気をつけましょう。

exports.handler = async (event, context, callback) => {
    const response = new Response();
    response.statusCode = 200;
    response.multiValueHeaders = { "Set-Cookie": [`KEY1=VALUE1`, `KEY2=VALUE2`] };
    response.body = JSON.stringify({ result: "succeed" });
    callback(null, response);
};

class Response {
    constructor() {
        this.statusCode = "";
        this.headers = {};
        this.multiValueHeaders = {};
        this.body = {};
    }
}
1
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?