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

Change the user agent to be more like a browser's user agent #1699

Merged
merged 1 commit into from Dec 4, 2013
Merged

Conversation

pjrobertson
Copy link
Member

@pjrobertson pjrobertson commented Dec 3, 2013

Since setting up gAnalytics for the plugin update system, most of the browser information is useless, since gAnalytics doesn't understand the current format we use for the User-Agent:

Quicksilver/4008 OSX/10.9.0 (x86)

So I've updated the user agent to more closely mimic that of typical browsers like Safari meaning gAnalytics should better understand it:

Quicksilver/4008 (Macintosh; Intel Mac OS X 10_9_0; cy-gb) (like Safari)

Things to note:

  • Safari uses like Gecko, I've put in like Safari - this should help with any browsers that reject requests based on User Agent. It's pretty interesting why Apple did it in the first place (search for Webkit). I think it's fine for us to pretend to be Safari? :P This is mostly useful when using QS to browse sites I guess
  • The locale in the user agent doesn't necessarily show the preferred locale of the current user, but shows the language they are using Quicksilver in. This was intentional. I think it's more interesting for us to know that "90% of people in Russia are using Quicksilver in Welsh" or whatever as opposed to "99% of people in Russia have their OS language set to Russian".
  • The word Intel is hard-coded, no need to test for PPC or x86_64 now (we can tell from the QS version)

Means sites like gAnalytics can better guess information
@skurfer
Copy link
Member

@skurfer skurfer commented Dec 3, 2013

Seems OK, but before I merge…

What about the update system? It’ll need to be changed so it knows how to get the OS version from the old and new style user-agent strings.

@pjrobertson
Copy link
Member Author

@pjrobertson pjrobertson commented Dec 3, 2013

Hmmm… good point. I’d completely forgotten about that :/

The update system already has to cope with 2 different user agent formats, I’ll just update it to take into account for this 3rd one - don’t merge yet, I’ll update the server first.

On 3 Rhag 2013, at 22:49, Rob McBroom notifications@github.com wrote:

Seems OK, but before I merge…

What about the update system? It’ll need to be changed so it knows how to get the OS version from the old and new style user-agent strings.


Reply to this email directly or view it on GitHub.

@pjrobertson
Copy link
Member Author

@pjrobertson pjrobertson commented Dec 4, 2013

OK, server updated to use the following code (@tiennou might be interested)

/*
Get the OS Version from the User Agent string.
OVer the years QS has used 3 User Agent forms:
* The standard CFNetwork User Agent
* And old one of the form 'Quicksilver/4008 OSX/10.9.0 (x86)'
* The current format (Nov 2013) of Quicksilver/4008 (Macintosh; Intel Mac OS X 10_9_0; cy-gb) (like Safari)

This function sniffs the $_SERVER user agent string testing these 3 types and returning a suitable OS
*/

function osVersionFromUserAgent($user_agent) {
    $os_version = null;
    if (preg_match_all("/.*OSX\/(\d{1,})\.(\d{1,})\.(\d{1,}).*/", $user_agent, $version_parts)) {
        // Old User Agent format
        $os_version = $version_parts[1][0] . str_pad ($version_parts[2][0] , 2, "0", STR_PAD_LEFT)
            . str_pad ($version_parts[3][0], 2, "0", STR_PAD_LEFT);
        debug("OS X Version, old user agent: " . $os_version);
    } else if (preg_match_all("/.*Mac OS X (\d{1,})_(\d{1,})_(\d{1,}).*/", $_SERVER['HTTP_USER_AGENT'], $version_parts)) {
        // New User Agent format (reflects Safari UA). See GH#1699
        $os_version = $version_parts[1][0] . str_pad ($version_parts[2][0] , 2, "0", STR_PAD_LEFT)  . str_pad ($version_parts[3][0], 2, "0", STR_PAD_LEFT);
        debug("OS X Version, new user agent string: " . $os_version);
    } else if (preg_match_all("/.*Darwin\/(\d{1,}\.\d{1,}(=?\.\d{1,})?).*/", $user_agent, $darwin_version)) {
        // CFNetwork User Agent
        $darwin_version = $darwin_version[1][0];
        $darwin_osx = unserialize(DARWIN_OSX);
        $os_version = $darwin_osx[$darwin_version];
        if ($os_version == null) {
            // Perhaps the key doesn't exist in DARWIN_OSX. Try and figure out what version of Darwin (and hence OS X) is being used
            $parts = explode(".", $darwin_version);
            if (sizeof($parts) == 3) {
                if ($parts[2] == "0") {
                    $darwin_version = $parts[0] . "." . $parts[1];
                } else {
                    $darwin_version = $parts[0] . "." . $parts[1] . ".0";
                }
            } else if (sizeof($parts) == 2) {
                $dar = $darwin_version . ".0";
            }
            $os_version = $darwin_osx[$darwin_version];
        }
        debug("Darwin version: ". $darwin_version . "\nOS X version: " . $os_version);
    }
    return $os_version;
}

@skurfer
Copy link
Member

@skurfer skurfer commented Dec 4, 2013

Using my Python script, it appears to return the right build number for the old and new style user agent. I even tried

Quicksilver/4000 (Macintosh; Intel Mac OS X 10_6_8; en-us) (like Safari)

though there will never be any such thing.

The only other thing I want to test is right-arrowing into some real world URLs, though I don’t expect to find any problems there.

@skurfer
Copy link
Member

@skurfer skurfer commented Dec 4, 2013

By the way @HenningJ, my previous comment triggered a build in Jenkins. It shouldn’t have as far as I can see.

EDIT: This one, too. Hopefully edits don’t do it. 😬

@pjrobertson
Copy link
Member Author

@pjrobertson pjrobertson commented Dec 4, 2013

Using my Python script, it appears to return the right build number for the old and new style user agent

You mean, you tested by just calling qs0.qsapp.com/plugins/check.php with various different user agents? Nice work. I'd done some testing as well, but it sounds like yours was beefier.

I don't see → into URLs changing much. If anything it may make things better (unless websites now hand down richer websites because they think we're safari, whereas previously they would have given us say the mobile website)

@skurfer
Copy link
Member

@skurfer skurfer commented Dec 4, 2013

Yeah, here’s the script if you want it.

https://gist.github.com/skurfer/7788433

You’ll need to install the Requests library, but surely everyone already has that. 😉

As you can see, it was originally used to see what list of plug-ins would be returned, so with some modifications, you can use it to test that, too.

skurfer added a commit that referenced this issue Dec 4, 2013
Change the user agent to be more like a browser's user agent
@skurfer skurfer merged commit 6338120 into master Dec 4, 2013
1 check passed
@skurfer skurfer deleted the user-agent branch Dec 4, 2013
@HenningJ
Copy link
Contributor

@HenningJ HenningJ commented Dec 4, 2013

By the way @HenningJ, my previous comment triggered a build in Jenkins. It shouldn’t have as far as I can see.

There was an additional "Trigger phrase " set as "build". I don't know why that exists in addition to the other (ok to test) phrase and it's not very well documented. ;-)

I removed that now, so just saying build won't trigger any confusing builds anymore. :-)

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

Successfully merging this pull request may close these issues.

None yet

3 participants