简体   繁体   中英

How to remove Cloudfront Headers on Viewer Response (Set-Cookie)

I would like to remove the "ASP.NET_SessionId" Set-Cookie header from the Cloudfront response.

set-cookie: lang=en;
set-cookie: lang-favorite=en;path=/
set-cookie: gxplang=E;
set-cookie: ASP.NET_SessionId=sdfdsf

Add a Lambda @Edge Function to the Viewer Response Behaviour of Cloudfront:

'use strict';

const discardHeader = 'ASP.NET_SessionId=';

exports.handler = (event, context, callback) => {
    const response = event.Records[0].cf.response;
    const setCookieHeaders = response.headers['set-cookie'];

    if(setCookieHeaders && setCookieHeaders.length > 0)
    {
        response.headers['set-cookie'] = setCookieHeaders.filter( h => h.value.indexOf(discardHeader) < 0 );
    }      
    return callback(null, response);    
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM