* fix http auth bug

This commit is contained in:
Stig Bakken 2002-03-19 19:30:06 +00:00
parent 529ec7cda4
commit 97beb58d43

View file

@ -35,12 +35,9 @@ class PEAR_Remote extends PEAR
// {{{ PEAR_Remote(config_object) // {{{ PEAR_Remote(config_object)
function PEAR_Remote($config = null) function PEAR_Remote(&$config)
{ {
$this->PEAR(); $this->PEAR();
if ($config === null) {
$config = &PEAR_Config::singleton();
}
$this->config = $config; $this->config = $config;
} }
@ -72,7 +69,7 @@ class PEAR_Remote extends PEAR
$password = $this->config->get('password'); $password = $this->config->get('password');
if ($username && $password) { if ($username && $password) {
$tmp = base64_encode("$username:$password"); $tmp = base64_encode("$username:$password");
$req_headers .= "Authorization: Basic $auth\r\n"; $req_headers .= "Authorization: Basic $tmp\r\n";
} }
fwrite($fp, ("POST /xmlrpc.php HTTP/1.0\r\n$req_headers\r\n$request")); fwrite($fp, ("POST /xmlrpc.php HTTP/1.0\r\n$req_headers\r\n$request"));
$response = ''; $response = '';
@ -84,9 +81,13 @@ class PEAR_Remote extends PEAR
case "200": case "200":
break; break;
case "401": case "401":
return $this->raiseError("PEAR_Remote: authorization required, please log in first"); if ($username && $password) {
return $this->raiseError("PEAR_Remote: authorization failed", 401);
} else {
return $this->raiseError("PEAR_Remote: authorization required, please log in first", 401);
}
default: default:
return $this->raiseError("PEAR_Remote: unexpected HTTP response: $matches[1] $matches[2]"); return $this->raiseError("PEAR_Remote: unexpected HTTP response: $matches[1] $matches[2]", (int)$matches[1]);
} }
while (trim(fgets($fp, 2048)) != ''); // skip rest of headers while (trim(fgets($fp, 2048)) != ''); // skip rest of headers
while ($chunk = fread($fp, 10240)) { while ($chunk = fread($fp, 10240)) {