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