Пример #1
0
 public function testGetURL()
 {
     $io = new \Composer\IO\NullIO();
     $req = new HttpGetRequest('packagist.org', 'https://packagist.org/packages.json', $io);
     self::assertSame('https://packagist.org/packages.json', $req->getURL());
     $req->host = 'packagist.jp';
     self::assertSame('https://packagist.jp/packages.json', $req->getURL());
     $req->scheme = 'http';
     $req->port = 8080;
     self::assertSame('http://packagist.jp:8080/packages.json', $req->getURL());
     $req->query += array('a' => 'b', 'c' => 'd');
     $req->scheme = '';
     self::assertSame('packagist.jp:8080/packages.json?a=b&c=d', $req->getURL());
 }
Пример #2
0
 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 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;
 }
 /**
  * @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()}";
 }