0

I've got a Viewer Response Lambda@Edge script that adds a Server-Timing header manually by reading other information from headers. This way, my JavaScript code can read this value and use it for other client-side functionality such as reporting.

export async function viewerResponse(event) {
  const { request, response } = event.Records[0].cf;
  response.headers['Server-Timing'] = [{ key: 'Server-Timing', value: 'something' }];
  return response;
}

So far so good. I can see the header being added at the edge.

However, when CloudFront registers a HIT (as seen by the header X-Cache: hit by cloudfront), the Server-Timing header mysteriously vanishes. It is as if CloudFront decides to override this header.

Has anyone seen anything like this? Can CloudFront be told to stop interfering?

I have tried to enable Server-Timing in CloudFront's security headers policy. This added CloudFront's own Server-Timing variables in addition to the custom stuff I wanted for any cache miss. But as soon as a cache hit occurs, the custom additions get removed.

Seth Jeffery
  • 1,110
  • 1
  • 8
  • 8

1 Answers1

0

Have you tried enabling the 'Server-Timing' header in your response CachePolicy in CloudFront?

enter image description here

Manu
  • 48
  • 7