public function testUpdate()
 {
     $req = new HttpGetRequest('github.com', 'https://api.github.com/repos/exampleorg/examplerepo/zipball/00000', new IO\NullIO());
     $preDownload = new JoinPoint('pre-download', $req);
     $redirect = new AspectRedirect();
     $redirect->update($preDownload);
     self::assertSame('https://codeload.github.com/exampleorg/examplerepo/legacy.zip/00000', $req->getURL());
 }
 public function before(HttpGetRequest $req)
 {
     if ('api.github.com' !== $req->host || !$req->maybePublic) {
         return;
     }
     $url = $req->getURL();
     if (preg_match('%^https://api\\.github\\.com/repos(/[^/]+/[^/]+/)zipball/%', $url, $m)) {
         $url = str_replace("api.github.com/repos{$m['1']}zipball", "codeload.github.com{$m['1']}legacy.zip", $url);
         $req->importURL($url);
     }
 }
 public function testGetCurlOpts()
 {
     $io = new \Composer\IO\NullIO();
     $req = new HttpGetRequest('packagist.org', 'https://packagist.org/packages.json', $io);
     $req->curlOpts[CURLOPT_TIMEOUT] = 10;
     $expects = array(CURLOPT_URL => 'https://packagist.org/packages.json', CURLOPT_TIMEOUT => 10, CURLOPT_HTTPGET => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 20, CURLOPT_ENCODING => 'gzip', CURLOPT_HTTPHEADER => array(), CURLOPT_VERBOSE => false);
     $curlOpts = $req->getCurlOpts();
     unset($curlOpts[CURLOPT_USERAGENT]);
     self::assertEquals($expects, $curlOpts);
     $req->username = '******';
     $req->password = '******';
     $expects[CURLOPT_USERPWD] = 'ninja:aieee';
     $curlOpts = $req->getCurlOpts();
     unset($curlOpts[CURLOPT_USERAGENT]);
     self::assertEquals($expects, $curlOpts);
 }
 public static function before(HttpGetRequest $req)
 {
     // no_proxy skip
     if (isset($_SERVER['no_proxy'])) {
         $pattern = new NoProxyPattern($_SERVER['no_proxy']);
         if ($pattern->test($req->getURL())) {
             $req->curlOpts[CURLOPT_PROXY] = null;
             return;
         }
     }
     $httpProxy = self::issetOr($_SERVER, 'http_proxy', 'HTTP_PROXY');
     if ($httpProxy && $req->scheme === 'http') {
         $req->curlOpts[CURLOPT_PROXY] = $httpProxy;
         return;
     }
     $httpsProxy = self::issetOr($_SERVER, 'https_proxy', 'HTTPS_PROXY');
     if ($httpsProxy && $req->scheme === 'https') {
         $req->curlOpts[CURLOPT_PROXY] = $httpsProxy;
         return;
     }
     $req->curlOpts[CURLOPT_PROXY] = null;
     $req->curlOpts[CURLOPT_PROXYUSERPWD] = null;
 }
 protected function promptAuth(Aspects\HttpGetRequest $req, Aspects\HttpGetResponse $res)
 {
     $io = $this->io;
     $httpCode = $res->info['http_code'];
     if ('github' === $req->special) {
         $message = "\nCould not fetch {$req->getURL()}, please create a GitHub OAuth token ";
         if (404 === $httpCode) {
             $message .= 'to access private repos';
         } else {
             $message .= 'to go over the API rate limit';
         }
         $github = new Util\GitHub($io, $this->config, null);
         if ($github->authorizeOAuth($req->origin)) {
             $this->retry = true;
             return;
         }
         if ($io->isInteractive() && $github->authorizeOAuthInteractively($req->origin, $message)) {
             $this->retry = true;
             return;
         }
         throw new Downloader\TransportException("Could not authenticate against {$req->origin}", 401);
     }
     if ('gitlab' === $req->special) {
         $message = "\nCould not fetch {$req->getURL()}, enter your {$req->origin} credentials ";
         if (401 === $httpCode) {
             $message .= 'to access private repos';
         } else {
             $message .= 'to go over the API rate limit';
         }
         $gitlab = new Util\GitLab($io, $this->config, null);
         if ($gitlab->authorizeOAuth($req->origin)) {
             $this->retry = true;
             return;
         }
         if ($io->isInteractive() && $gitlab->authorizeOAuthInteractively($req->origin, $message)) {
             $this->retry = true;
             return;
         }
         throw new Downloader\TransportException("Could not authenticate against {$req->origin}", 401);
     }
     // 404s are only handled for github
     if (404 === $httpCode) {
         return;
     }
     // fail if the console is not interactive
     if (!$io->isInteractive()) {
         switch ($httpCode) {
             case 401:
                 $message = "The '{$req->getURL()}' URL required authentication.\nYou must be using the interactive console to authenticate";
                 break;
             case 403:
                 $message = "The '{$req->getURL()}' URL could not be accessed.";
                 break;
         }
         throw new Downloader\TransportException($message, $httpCode);
     }
     // fail if we already have auth
     if ($io->hasAuthentication($req->origin)) {
         throw new Downloader\TransportException("Invalid credentials for '{$req->getURL()}', aborting.", $res->info['http_code']);
     }
     $io->overwrite("    Authentication required (<info>{$req->host}</info>):");
     $username = $io->ask('      Username: '******'      Password: ');
     $io->setAuthentication($req->origin, $username, $password);
     $this->retry = true;
 }
 protected function promptAuth(Aspects\HttpGetRequest $req, Aspects\HttpGetResponse $res)
 {
     $this->_retry = $req->promptAuth($res, $this->config, $this->io);
 }
 /**
  * @param string $url
  * @return string
  */
 private function makeDownloadingText($url)
 {
     $request = new Aspects\HttpGetRequest('example.com', $url, $this->io);
     $request->query = array();
     return "    <comment>{$this->successCnt}/{$this->totalCnt}</comment>:    {$request->getURL()}";
 }
 public function getCurlOpts()
 {
     $curlOpts = parent::getCurlOpts();
     return $curlOpts;
 }