How can I get all set-cookie headers from response object in ResponseWriter?

We can set/remove headers, but we can’t get headers list from response, because response object comes empty (like { }).
How can I get all set-cookie headers from response object in ResponseWriter?

code example:

import { RouteHandler } from ‘@layer0/core/router/Router’;
import { HTTP_HEADERS } from “@layer0/core”;
import transformResponse from ‘…/transform’;

const handler: RouteHandler = async (obj) => {
const {
cache,
removeUpstreamResponseHeader,
updateResponseHeader,
setResponseHeader,
proxy,
updateUpstreamResponseHeader,
request,
response,
} = obj;
console.log('Current response → ', response)
setResponseHeader(HTTP_HEADERS.cacheControl, ‘public, max-age=86400’); // change the cache headers to be cachable

proxy(‘origin’, { transformResponse });
}

export default handler;

Thanks

In your example, you are trying to log the response before the request was even made so the response will always be empty.

Once the response is received from your origin, you can see the headers of the response from transformResponse:

proxy('origin', {
      transformResponse: res => {
        console.log('Upstream headers:', res.getHeader('set-cookie'))
      },
})
1 Like