1

I'm working on an hybrid mobile application, and I'd really benefit of having the app version, OS build and screen sizes of the users that issue our API, just to know if issues come up due to a poorly developed feature or a bugfix that can't fulfill everyone's problems. That way, in a semi transparent procedure I'd be able to track this. I've been testing it with some users, and it works like a charm in ones, but others complain about strange errors that occur upon downloading files from our CDNs.

Could modifying the User Agent affect the download requests for a server, and only affect specific users?

PS: I decided to change the user agent, since some of the info I want is "native code related", and setting that in the user agent would mean no change in the current API calls.

  • 2
    How are you making the change to User-Agent? XHR? What does "native code related" mean? In general, I think logging through a separate API call is more robust. I'm not aware of any guarantee that User-Agent will always get through, and using a separate call permits confirming to the client the log info was received. – cxw Jul 15 '15 at 9:47
  • @cxw native code stands by code in the platform specific language (Java for Android, Objective-C or Swift for iOS). Hybrid means javascript, in my case. The change is done on the application creation. I already have alternate calls to define the best protocol to make calls. That works, so that's why I thought it could be download related – Korcholis Jul 15 '15 at 10:36
2

The easiest way to find out is to disable the User-Agent customization and see if the problem goes away :) .

In general, User-Agent is not guaranteed to be what you set. For example, a corporate firewall might use deep packet inspection to rewrite User-Agent and reduce browser entropy.

Philosophically, I think modifying User-Agent to include additional logging information is a bad idea because it violates the single responsibility principle (as applied to data - hear me out). Assume everyone's browser is standards-compliant. (Your hybrid app is compliant, right? :) ) On mobile devices, User-Agent has a well-defined responsibility: to indicate the user's preference for mobile or desktop rendering. Google says:

HTTP redirection is a commonly used to redirect clients to device-specific URLs. Usually, the redirection is done based on the user-agent in the HTTP request headers.

Is it ridiculous that a 109-byte (for me) string serves to convey a single bit of information? Sure, but that's the world we live in.

Rewriting User-Agent to add logging information gives that string a second responsibility. That means your servers, CDN, logging tools, and everything else have to know about (or at least tolerate) both the logging information and the mobile/desktop intent information. Whenever you want to change the logging info, you have to make sure you're not breaking anything related to rendering intent, and vice versa.

Even though it may be a pain now, do yourself and those who maintain your code a favor: don't overload User-Agent. Splitting responsibilities to keep your code simple and loosely coupled will pay for itself many times over by saving time, reducing stress, and preventing hair loss.

| improve this answer | |
  • I disagree with your assertion that the responsibility of the UA string on mobile devices is just to indicate a desktop/mobile site preference - the user agent serves as a general source of information about the OS and browser. – Sam Dufel Jul 15 '15 at 16:52
  • @SamDufel, sure. Hence the admittedly dicey assumption in the answer that all browsers are standards-compliant. Someday, though, when we don't have to check IE versions or moz/safari/... extension support, the software identity information will be nice-to-have, not have-to-have. "The idea [of HTML] was that the language was independent of the formatter (the browser or other viewing software) which actually displayed the text on the screen." - Dave Raggett, w3.org/People/Raggett/book4/ch02.html – cxw Jul 15 '15 at 17:12
  • 1
    It took quite a while to reimplement all the api calls, but we ended leaving the UA as it was, and stuffing any needed info as other parameters. Thanks @cxw! – Korcholis Jul 24 '15 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.