Ticket #5065 (closed enhancement: duplicate)

Opened 1 year ago

Last modified 1 month ago

Unify User-Agent strings

Reported by: docwhat Assigned to: jacobsantos
Priority: normal Milestone:
Component: General Version:
Severity: normal Keywords: privacy user-agent
Cc:

Description

In WordPress 2.3, there are either 10 or 11 places where User-Agent strings are created.

I would like to suggest adding a function, wp_user_agent() which would generate the base User-Agent including things like PHP version and bloginfo('url'). It could optionally take an array (in hash form) to append extra values, like Akismet version, etc.

Example Usage:

$http_response .= "User-Agent: ".wp_user_agent(Array('Akismet' => '2.0'));

This would prevent repetition of code and allow for admins or plugin developers to add or remove information they are not comfortable sending out.

Ciao!

Attachments

wp-user-agent-filtered.diff (5.4 kB) - added by Otto42 on 09/26/07 21:28:09.
Filtered patch
wp-user-agent.patch (6.1 kB) - added by docwhat on 09/27/07 01:51:18.
Best version - includes filter and akismet changes.
wp-free-agent.php (0.9 kB) - added by docwhat on 09/27/07 04:48:30.

Change History

09/26/07 17:48:47 changed by docwhat

I have attached patch. I tried to follow the coding style as best as I could.

I changed the way the bloginfo('url') is appended to the user agent because id didn't follow RFC 2068. I put it in a comment (parenthesis) instead. I don't think that's an issue because according to photomatt, it isn't being used yet.

Ciao!

09/26/07 17:52:56 changed by docwhat

Also, my patch deliberately didn't change the Incutio and Snoopy UA strings, since they didn't seem to reflect anything. I don't actually understand when they are called, so I'm not sure what difference it makes.

Ciao!

09/26/07 17:58:31 changed by docwhat

Okay, I just updated the patch because I missed the magpie stuff. I'm not quite sure about the code that adds a trailing ')' to the user-agent, but I don't think the output would be changed in anyway.

My only other concern is that the define at the top may be called too early for the wp_user_agent() function to be available.

Ciao!

09/26/07 18:15:33 changed by docwhat

Added bug #5085, which is similar in spirit, though more complex.

09/26/07 18:51:48 changed by docwhat

Okay, this isn't complete.

It needs some sort of filter hook thingy. I'm not familiar with doing that. Can someone point me at an example or suggest a mechanism to do this?

Otherwise, you cannot write a plugin to disable or change it. :-/

Ciao!

09/26/07 21:27:44 changed by Otto42

Attaching the same patch with a filter on wp_user_agent output.

09/26/07 21:28:09 changed by Otto42

  • attachment wp-user-agent-filtered.diff added.

Filtered patch

09/27/07 01:50:31 changed by docwhat

That was so easy. Neat! Thanks Otto42!

I thought the filter might have to be pre-registered or something.

I'm going to update the patch (mine) one more time to add the filter, and to add the missing akismet plugin patch (because that's needed too).

Then I'll attach the plugin to anonymize the ua.

Ciao!

09/27/07 01:51:18 changed by docwhat

  • attachment wp-user-agent.patch added.

Best version - includes filter and akismet changes.

09/27/07 01:52:46 changed by docwhat

Alrighty!

Now how do we get it approved and into the svn tree?

Ciao!

09/27/07 01:58:54 changed by foolswisdom

  • keywords changed from privacy user-agent to privacy user-agent has-patch.
  • milestone changed from 2.5 to 2.4.

09/27/07 04:48:30 changed by docwhat

  • attachment wp-free-agent.php added.

09/27/07 10:13:07 changed by f00f

  • milestone changed from 2.4 to 2.3.1.

+1

09/27/07 17:03:28 changed by foolswisdom

  • milestone changed from 2.3.1 to 2.4.

f00f, please don't change milestones. There is severe symptom that would justify putting this in a maint. release.

11/14/07 20:37:51 changed by docwhat

Update:

I've been running this patch (with the plugin) for over a month with no problems.

Ciao!

11/15/07 08:52:45 changed by DD32

I'm thinking a better method might be to wrap all outgoing http requests into a WP function. Currently theres a fair few fsockopen() scattered around the place, and theres Snoopy too, What would be better is a function such as:

function wp_get_remote($url,$headers=false){
...
$userAgent = apply_filters('useragent',get_the_useragent());
...
fsockopen()...
if(!$headers)
return $html;
else
return array($html,$headers);
}

(Similar to wp_get_http_headers())

Just makes more sense than changing the user agents in all these different locations to me, Why change the code in so many places when it could all just be consolidated in one swoop?, It would also help in adding Global Proxy support in.

(Probably new ticket material, infact, i swear there is one, i just cant find it).

11/15/07 14:41:37 changed by santosj

Yeah. Maybe #4779 is what you were looking for DD32?

03/19/08 22:41:24 changed by ffemtcj

  • milestone changed from 2.5 to 2.6.

With the changes in 2.5 is this still valid?

07/17/08 03:45:12 changed by jacobsantos

  • owner changed from anonymous to jacobsantos.

07/17/08 03:45:17 changed by jacobsantos

  • status changed from new to assigned.

08/04/08 17:46:19 changed by santosj

  • status changed from assigned to closed.
  • resolution set to duplicate.
  • milestone deleted.

This is mostly implemented in #4779. The API isn't used everywhere, but it eventually will be.

08/04/08 17:46:27 changed by santosj

  • keywords changed from privacy user-agent has-patch to privacy user-agent.