1
0
Fork 0

Send headers as array instead of one big string

pull/1191/merge
Jordi Boggiano 2012-10-19 11:02:18 +02:00
parent 73aea05907
commit 43c21a736c
1 changed files with 18 additions and 14 deletions

View File

@ -260,31 +260,35 @@ class RemoteFilesystem
protected function getOptionsForUrl($originUrl, $additionalOptions)
{
$header = sprintf(
"User-Agent: Composer/%s (%s; %s; PHP %s.%s.%s)\r\n",
$headers = array(
sprintf(
'User-Agent: Composer/%s (%s; %s; PHP %s.%s.%s)',
Composer::VERSION === '@package_version@' ? 'source' : Composer::VERSION,
php_uname('s'),
php_uname('r'),
PHP_MAJOR_VERSION,
PHP_MINOR_VERSION,
PHP_RELEASE_VERSION
)
);
if (extension_loaded('zlib')) {
$header .= 'Accept-Encoding: gzip'."\r\n";
$headers[] = 'Accept-Encoding: gzip';
}
if ($this->io->hasAuthorization($originUrl)) {
$auth = $this->io->getAuthorization($originUrl);
$authStr = base64_encode($auth['username'] . ':' . $auth['password']);
$header .= "Authorization: Basic $authStr\r\n";
$headers[] = 'Authorization: Basic '.$authStr;
}
$options = array_replace_recursive($this->options, $additionalOptions);
if (isset($options['http']['header'])) {
$options['http']['header'] = rtrim($options['http']['header'], "\r\n") . "\r\n" . $header;
} else {
$options['http']['header'] = $header;
if (isset($options['http']['header']) && !is_array($options['http']['header'])) {
$options['http']['header'] = explode("\r\n", trim($options['http']['header'], "\r\n"));
}
foreach ($headers as $header) {
$options['http']['header'][] = $header;
}
return $options;