Page MenuHomePhabricator

Http::get should accept user-agent option
Closed, ResolvedPublic

Description

Author: olivier.beaton

Description:
for any extension that uses Http::get a common task is setting the user-agent, which means they have to use the request object instead. Really $options should include the user-agent string


Version: unspecified
Severity: enhancement

Details

Reference
bz31072

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 21 2014, 11:57 PM
bzimport set Reference to bz31072.
bzimport added a subscriber: Unknown Object (MLST).

Most sensible thing may be to just accept a 'headers' key with a map of HTTP headers to set.

Thus:

$foo = Http::get($url, array(

'followRedirects' => false,
'postData' => array(
  'foo' => 'bar',
  'baz' => 'quux',
),
'headers' => array(
  'User-Agent': 'my special extension',
  'Accept': 'application/x-something',
)

);

olivier.beaton wrote:

Doing some compat testing and I found out that this is actually lost functionality. Here's what Http::get looked like in 1.15

public static function get( $url, $timeout = 'default', $opts = array() ) {

return Http::request( "GET", $url, $timeout, $opts );

public static function request( $method, $url, $timeout = 'default', $curlOptions = array() ) {

and $curlOptions can accept CURLOPT_USERAGENT

...reviving that would be a bit of a hack though. CURL isn't the only thing we support.

Created attachment 9087
Implement UA at Http::request() level

I'm not so sure it's that hard or that hacky.

Attached: