読者です 読者をやめる 読者になる 読者になる

プロキシ環境下で composer でインストール出来なくなった(HTTP/1.0 400 Bad Request)

なぜか自社の社内から zf2 や phpunit が composer でインストール出来ない・・・少し前まで出来ていたはずなのに

$ cat composer.json
{
    "require": {
        "zendframework/zendframework": ">2.1.3"
    }
}

$ php composer.phar install -vvv
Downloading composer.json
Loading composer repositories with package information
Downloading https://packagist.org/packages.json
Installing dependencies
Downloading https://packagist.org/p/provider-latest$14352611280bf26607b536d9846c4ce932ba0013938437039481370f12ff5a00.json
  - Installing zendframework/zendframework (2.1.5)
Downloading https://api.github.com/repos/zendframework/zf2/zipball/release-2.1.5
    Downloading: connection...
                                                                                                                                      
  [Composer\Downloader\TransportException]                                                                                            
  The "https://api.github.com/repos/zendframework/zf2/zipball/release-2.1.5" file could not be downloaded (HTTP/1.0 400 Bad Request)  
                                                                                                                                      
Exception trace:
 () at phar:///tmp/zf/composer.phar/src/Composer/Util/RemoteFilesystem.php:243
 Composer\Util\RemoteFilesystem->callbackGet() at n/a:n/a
 file_get_contents() at phar:///tmp/zf/composer.phar/src/Composer/Util/RemoteFilesystem.php:123
 Composer\Util\RemoteFilesystem->get() at phar:///tmp/zf/composer.phar/src/Composer/Util/RemoteFilesystem.php:61
 Composer\Util\RemoteFilesystem->copy() at phar:///tmp/zf/composer.phar/src/Composer/Downloader/FileDownloader.php:106
 Composer\Downloader\FileDownloader->download() at phar:///tmp/zf/composer.phar/src/Composer/Downloader/ArchiveDownloader.php:31
 Composer\Downloader\ArchiveDownloader->download() at phar:///tmp/zf/composer.phar/src/Composer/Downloader/DownloadManager.php:177
 Composer\Downloader\DownloadManager->download() at phar:///tmp/zf/composer.phar/src/Composer/Installer/LibraryInstaller.php:155
 Composer\Installer\LibraryInstaller->installCode() at phar:///tmp/zf/composer.phar/src/Composer/Installer/LibraryInstaller.php:86
 Composer\Installer\LibraryInstaller->install() at phar:///tmp/zf/composer.phar/src/Composer/Installer/InstallationManager.php:151
 Composer\Installer\InstallationManager->install() at phar:///tmp/zf/composer.phar/src/Composer/Installer/InstallationManager.php:138
 Composer\Installer\InstallationManager->execute() at phar:///tmp/zf/composer.phar/src/Composer/Installer.php:505
 Composer\Installer->doInstall() at phar:///tmp/zf/composer.phar/src/Composer/Installer.php:208
 Composer\Installer->run() at phar:///tmp/zf/composer.phar/src/Composer/Command/InstallCommand.php:97
 Composer\Command\InstallCommand->execute() at phar:///tmp/zf/composer.phar/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:244
 Symfony\Component\Console\Command\Command->run() at phar:///tmp/zf/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:882
 Symfony\Component\Console\Application->doRunCommand() at phar:///tmp/zf/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:212
 Symfony\Component\Console\Application->doRun() at phar:///tmp/zf/composer.phar/src/Composer/Console/Application.php:117
 Composer\Console\Application->doRun() at phar:///tmp/zf/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:119
 Symfony\Component\Console\Application->run() at phar:///tmp/zf/composer.phar/src/Composer/Console/Application.php:83
 Composer\Console\Application->run() at phar:///tmp/zf/composer.phar/bin/composer:43
 require() at /tmp/zf/composer.phar:15

社内はプロキシ経由じゃないと外に出られないのでプロキシ関連が怪しいだろうと思って調べてみたら・・・

HTTP_PROXY_REQUEST_FULLURI

If you use a proxy but it does not support the request_fulluri flag, then you should set this env var to false or 0 to prevent composer from setting the request_fulluri option.

次のように HTTP_PROXY_REQUEST_FULLURI を指定したら上手く行きました(もちろん http_proxy/https_proxy環境変数に設定済で)。

$ HTTP_PROXY_REQUEST_FULLURI=0 php composer.phar install -vvv
Downloading composer.json
Loading composer repositories with package information
Downloading https://packagist.org/packages.json
Installing dependencies
Downloading https://packagist.org/p/provider-latest$f8ad15c689b847def83135a206e9500352272945ea490d599cdb0a7ff2b0d8df.json
  - Installing zendframework/zendframework (2.1.5)
Downloading https://api.github.com/repos/zendframework/zf2/zipball/release-2.1.5
    Downloading: 100%         
    Extracting archive

    REASON: Required by root: zendframework/zendframework

zendframework/zendframework suggests installing doctrine/common (Doctrine\Common >=2.1 for annotation features)
zendframework/zendframework suggests installing ext-intl (ext/intl for i18n features)
zendframework/zendframework suggests installing ircmaxell/random-lib (Fallback random byte generator for Zend\Math\Rand if OpenSSL/Mcrypt extensions are unavailable)
zendframework/zendframework suggests installing pecl-weakref (Implementation of weak references for Zend\Stdlib\CallbackHandler)
zendframework/zendframework suggests installing zendframework/zendpdf (ZendPdf for creating PDF representations of barcodes)
zendframework/zendframework suggests installing zendframework/zendservice-recaptcha (ZendService\ReCaptcha for rendering ReCaptchas in Zend\Captcha and/or Zend\Form)
Writing lock file

少し前まで大丈夫だったのになぜ急に HTTP_PROXY_REQUEST_FULLURI の指定が必要になったのか不可解です。 (自社のプロキシの問題かもしれないので composer や github のせいとは限らない)

追記 2013-06-03

宛先が https の場合は HTTPS_PROXY_REQUEST_FULLURI にする必要があります(この記事を書いた時点では HTTP_PROXY_REQUEST_FULLURI だけで十分でしたが)。

追記 2013-06-04

HTTP(S)_PROXY_REQUEST_FULLURI を 0 にすれば上手くいく場合と 1 にすれば上手くいく場合があってよくわからない・・・