WordPress / Requests

Requests for PHP is a humble HTTP request library. It simplifies how you interact with other sites and takes away all your worries.
https://requests.ryanmccue.info/
Other
3.57k stars 493 forks source link

When using the hook system, multiple auth hooks are dispatched, and hence creates multiple auth headers #242

Open ramesh-tr opened 7 years ago

ramesh-tr commented 7 years ago

Steps to reproduce - Use the following sript

$hooks = new Requests_Hooks();

$hooks->register('fsockopen.before_send', function (&$data){
    var_dump( $data );
});

$headers = array('Accept' => 'application/json');
$options = array('auth' => array('user', 'pass'), 'hooks' => $hooks, 'transport' => 'Requests_Transport_fsockopen');
$request = Requests::get('https://api.github.com/gists', $headers, $options);
$request = Requests::get('https://api.github.com/gists', $headers, $options);

The result from the above script execution

string(221) "GET /gists HTTP/1.0
Host: api.github.com:443
User-Agent: php-requests/1.6.1
Accept-Encoding: deflate;q=1.0, compress;q=0.5, gzip;q=0.5
Accept: application/json
Authorization: Basic dXNlcjpwYXNz
Connection: Close

" string(256) "GET /gists HTTP/1.0
Host: api.github.com:443
User-Agent: php-requests/1.6.1
Accept-Encoding: deflate;q=1.0, compress;q=0.5, gzip;q=0.5
Accept: application/json
Authorization: Basic dXNlcjpwYXNz
Authorization: Basic dXNlcjpwYXNz
Connection: Close

"

Note that on the second request, there are two Authorization header. Similarly, for the third request, there will be three Authorization headers added to the request.

rmccue commented 7 years ago

This is (somewhat) intentional; the hooks system is per-request. I would like to consider changing that at some point however.