Dotclear


Ignore:
Timestamp:
07/01/15 14:23:38 (10 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Add  http:// scheme in not present in URL, better cope with netHttp::initClient() error, fixes #2091

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.store.php

    r2566 r3025  
    195195     public function download($url, $dest) 
    196196     { 
    197           try { 
    198                $client = netHttp::initClient($url, $path); 
    199                $client->setUserAgent($this->user_agent); 
    200                $client->useGzip(false); 
    201                $client->setPersistReferers(false); 
    202                $client->setOutput($dest); 
    203                $client->get($path); 
    204                unset($client); 
    205           } 
    206           catch (Exception $e) { 
    207                unset($client); 
     197          // Check and add default protocol if necessary 
     198          if (!preg_match('%^http[s]?:\/\/%',$url)) { 
     199               $url = 'http://'.$url; 
     200          } 
     201          // Download package 
     202          if ($client = netHttp::initClient($url, $path)) { 
     203               try { 
     204                    $client->setUserAgent($this->user_agent); 
     205                    $client->useGzip(false); 
     206                    $client->setPersistReferers(false); 
     207                    $client->setOutput($dest); 
     208                    $client->get($path); 
     209                    unset($client); 
     210               } 
     211               catch (Exception $e) { 
     212                    unset($client); 
     213                    throw new Exception(__('An error occurred while downloading the file.')); 
     214               } 
     215          } else { 
    208216               throw new Exception(__('An error occurred while downloading the file.')); 
    209217          } 
Note: See TracChangeset for help on using the changeset viewer.

Sites map