Zen
Zen

Reputation: 11

How do I get CloudFront-Viewer-Country to appear in browser request headers?

I have a cloudfront for S3 that my application is calling to get the assets. I have a origin request policy that has "Headers - Include the following headers > CloudFront-Viewer-Country and CloudFront-Viewer-City" . Despite this, when I check the request headers in the browser console, i don't see any of those two when I can see the "Hit from cloudfront" in the response headers. I'm able to modify response headers and it shows the change in the browser but any headers wherther it be Cloutfront-viewer-* or any custom header that I add are not showing.

I've also tried adding cloudfront function to behaviors > function associations > viewer request

function handler(event) {
    const request = event.request;
    const clientIP = event.viewer.ip;
    
    //Add the true-client-ip header to the incoming request
    request.headers['viewer-ip'] = {value: clientIP};
    
    return request;
}

as well as adding this lambda@edge function to the behaviors > function associations > origin request

'use strict';

export const handler = async (event, context, callback) => {
   const request = event.Records[0].cf.request; 
   request.headers['my-test-header'] = [{ key: 'my-test-header', value: 'Test Value' }];
   return callback(null,request);
};

But any of those headers are not showing. I've been following these documentations too but it seems to be not working.

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/controlling-origin-requests.html https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location.

I also saw this question but I couldn't get mine to work How do I get CloudFront-Viewer-Country to appear in response headers?

Am I doing something wrong or am I missing something?

Upvotes: 0

Views: 604

Answers (1)

Ankit Patro
Ankit Patro

Reputation: 1

Check <Application-URL>/smth.jsp

It'll give you a list of HTTP Headers

Upvotes: 0

Related Questions