为什么 AWS Cloudfront 不将平板电脑设备归类为平板电脑?

Why AWS Cloudfront not classifying Tablet device as Tablet?

下面是我的 Lambda 代码。

当我输入 lambda 时,我可以得到 'Desktop' 或 'Mobile'。当我发送 Tablet UserAgent 时,它没有将其归类为 Tablet。

exports.handler = (event, context, callback) => {
    var region = process.env.AWS_REGION ? process.env.AWS_REGION : 'us-east-1';
    console.log(region);
    console.log(event);

    var device = {};
    if( event.headers['CloudFront-Is-Mobile-Viewer']  === "true" )
         device.device = 'Mobile';
    else if ( event.headers['CloudFront-Is-Tablet-Viewer']  === "true" )
         device.device = 'Tablet';
     else
         device.device = 'Desktop';

     var response = {
        statusCode: 200,
        body: JSON.stringify(device)
    };

    callback(null, response);
};

我也仔细检查了接收到 lambda 的 headers。

'CloudFront-Is-Desktop-Viewer': 'true',
'CloudFront-Is-Mobile-Viewer': 'false',
'CloudFront-Is-SmartTV-Viewer': 'false',
'CloudFront-Is-Tablet-Viewer': 'false',
'CloudFront-Viewer-Country': 'US',

User-Agent:

Mozilla/5.0 (iPad; CPU OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B410 Safari/600.1.4

Based on the value of the User-Agent header, CloudFront sets the value of these headers to true or false before forwarding the request to your origin. If a device falls into more than one category, more than one value might be true. For example, for some tablet devices, CloudFront might set both CloudFront-Is-Mobile-Viewer and CloudFront-Is-Tablet-Viewer to true. (emphasis added)

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/header-caching.html#header-caching-web-device

因此,如果您将它们向下转换为单一设备分类,那么如果您按此顺序测试它们并在第一个匹配处停止,您可能会得到最合理的结果:

CloudFront-Is-SmartTV-Viewer
CloudFront-Is-Tablet-Viewer
CloudFront-Is-Mobile-Viewer
CloudFront-Is-Desktop-Viewer