Reputation: 1120
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.
Upvotes: 0
Views: 233
Reputation: 194
I'm not familiar with CloudFront, or some of the other details of what you're talking about. However, is it not simply that when something is served from a cache, your script is not creating/adding to the response header because the cache mechanism itself is in fact creating the response header for the cached resource? Or perhaps I just don't understand all the 'edge' business ; )
Upvotes: 0
Reputation: 58
Have you tried enabling the 'Server-Timing' header in your response CachePolicy in CloudFront?
Upvotes: 0