Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage behind a CDN #50

Closed
fernandobandeira opened this issue Sep 5, 2019 · 2 comments
Closed

Usage behind a CDN #50

fernandobandeira opened this issue Sep 5, 2019 · 2 comments

Comments

@fernandobandeira
Copy link

fernandobandeira commented Sep 5, 2019

CDNs usually don't forward the user-agents to the servers, or they override it with their own user-agent, usually ins this situation, they send some custom headers with the requisition, cloudfront for example:

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

Would a feature that allows the developer to pass in their own custom uaresults to the provider or something similar make sense in this case?

A workaround / alternative I'm using in the moment is to just fake a ua in the code and pass it down to the provider...

if (userAgent === 'Amazon CloudFront') {
  userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36';
  if (props.ctx.req.headers['cloudfront-is-tablet-viewer'] === 'true') {
    userAgent = 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1';
  } else if (props.ctx.req.headers['cloudfront-is-mobile-viewer'] === 'true') {
    userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1';
  }
}

Great library btw, ty for making it open sourced.
Feel free to close it if you think the dev should just use the workaround, just posting this to bring up some ideas and a place where ppl can find a workaround if they face this problem.

@quentin-sommer
Copy link
Owner

quentin-sommer commented Sep 10, 2019

Hi,

Indeed it's annoying that CDN's don't forward the request user-agent... This library is just a simpler api around the ua-parser-js library so I prefer to avoid escape hatches like allowing users to override the results themselves.

I think your solution is perfectly fine! I would just write tests to make sure the "fake detection" doesn't break in a future version of ua-parser-js (unlikely but you never know)

Cheers

@quentin-sommer
Copy link
Owner

I'll go ahead and close this issue. Feel free to open a new one if you need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants