Пример #1
0
 function testCheckMimeType()
 {
     $http = new HttpHeader();
     $this->assertTrue($http->checkMimeType('audio/mpeg', 'file'));
     $this->assertTrue($http->checkMimeType('image/png', 'img'));
     $this->assertTrue($http->checkMimeType('text/html', 'html'));
     $this->assertFalse($http->checkMimeType('image/png', 'html'));
 }
Пример #2
0
 public function load($url)
 {
     $descriptor =& $this->getDescriptor();
     $this->setOption($descriptor, CURLOPT_URL, $url);
     $this->setOptions($descriptor);
     $answer = $this->exec();
     $descriptor['info'] = curl_getinfo($descriptor['descriptor']);
     $descriptor['info']['error'] = curl_error($descriptor['descriptor']);
     $descriptor['info']['header'] = HttpHeader::cutHeader($answer);
     if (HttpHeader::isRedirect($descriptor['info']['http_code'])) {
         if ($this->useRedirect()) {
             $this->setReferer($url, $descriptor);
             $answer = $this->load($descriptor['info']['redirect_url']);
         }
     }
     $this->setRedirectCount(0);
     $this->setAnswer($answer);
     $this->reInit();
     return $this->getAnswer();
 }
Пример #3
0
 public function load($url = [])
 {
     $goodAnswer = [];
     $countMultiStream = $this->getCountStream();
     $this->setCountCurl(count($url));
     $descriptorArray =& $this->getDescriptorArray();
     $descriptorKey = 0;
     $urlDescriptorsLink = [];
     foreach ($url as $keyUrl => $valueUrl) {
         for ($i = 0; $i < $countMultiStream; $i++) {
             $urlDescriptorsLink[$keyUrl][] = $descriptorKey;
             if (isset($descriptorArray[$descriptorKey]['descriptor'])) {
                 $this->setOption($descriptorArray[$descriptorKey], CURLOPT_URL, $valueUrl);
             }
             $descriptorKey++;
         }
     }
     foreach ($descriptorArray as &$value) {
         $this->setOptions($value);
     }
     $this->resetDescriptors();
     $answer = $this->exec();
     foreach ($answer as $key => &$value) {
         $descriptorArray[$key]['info'] = curl_getinfo($descriptorArray[$key]['descriptor']);
         $descriptorArray[$key]['info']['error'] = curl_error($descriptorArray[$key]['descriptor']);
         $descriptorArray[$key]['info']['header'] = HttpHeader::cutHeader($value);
         $linkKey = $this->getLinkKey($urlDescriptorsLink, $key);
         $goodAnswer[$linkKey][$key] = $value;
     }
     $this->setAnswer($goodAnswer);
     return $this->getAnswer();
 }