80,6 → 80,7 |
$ch = curl_init($this->url); |
curl_setopt($ch, CURLOPT_HEADER, TRUE); |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
|
if($mode == 'POST') curl_setopt($ch, CURLOPT_POST, TRUE); |
elseif($mode == 'PUT') curl_setopt($ch, CURLOPT_PUT, TRUE); |
87,18 → 88,26 |
|
if($donnees) curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($donnees, null, self::HTTP_URL_REQUETE_SEPARATEUR)); |
|
// curl_setopt($ch, CURLOPT_COOKIE, "XDEBUG_PROFILE"); // debug |
/* if(isset($_COOKIES["XDEBUG_PROFILE"])) curl_setopt($ch, CURLOPT_COOKIE, "XDEBUG_PROFILE"); |
$caller = self::getCaller(debug_backtrace()); |
@curl_setopt($ch, CURLOPT_REFERER, sprintf("%s[%s:%d:%s]", $_SERVER['REQUEST_URI'], $caller['file'], $caller['line'], $caller['function'])); // $_SERVER['QUERY_STRING']; // debug */ |
$flux = curl_exec($ch); |
curl_close($ch); |
|
if (!$flux) { |
$this->reponse_entetes = $http_response_header; |
$e = "L'ouverture de l'url '{$this->url}' par la méthode HTTP '$mode' a échoué!"; |
trigger_error($e, E_USER_WARNING); |
trigger_error(sprintf("fail: %s \"%s\" (%s)", strtoupper($mode), $this->url, http_build_query($donnees, null, self::HTTP_URL_REQUETE_SEPARATEUR)), |
E_USER_WARNING); |
} else { |
list($this->reponse_entetes, $contenu) = explode("\r\n\r\n", $flux, 2); |
// attention, CURLOPT_FOLLOWLOCATION amène le stream à contenir plusieurs section d'header HTTP successives |
$t = explode("\r\n\r\n", $flux); |
$contenu = array_splice($t, -1); |
$dernier_entete = array_splice($t, -1); |
$contenu = $contenu[0]; |
$dernier_entete = $dernier_entete[0]; |
|
// XXX: mimic stream_get_meta_data() (ce qui n'est pas très propre, le code appelant ferait mieux de se mettre à jour) |
$this->reponse_entetes = array('wrapper_data' => explode("\r\n", $this->reponse_entetes)); |
$this->reponse_entetes = array('wrapper_data' => explode("\r\n", $dernier_entete)); |
} |
$this->traiterEntete(); |
} |
106,8 → 115,13 |
return $contenu; |
} |
|
static function getCaller($trace) { |
foreach($trace as $v) if(strpos($v['file'], '/modules/') !== false) return $v; |
return NULL; |
} |
|
public function envoyerRequete($url, $mode, Array $donnees = array()) { |
// debug: error_log("$mode {$this->url}"); |
// error_log("framework/envoyerRequete: $mode $url"); |
|
// nous n'activons le wrapper que pour GET pour l'instant |
// car l'utilisation de curl pour les autres modes pourrait |
133,8 → 147,9 |
$flux = @fopen($this->url, 'r', false, $contexte); |
if (!$flux) { |
$this->reponse_entetes = $http_response_header; |
$e = "L'ouverture de l'url '{$this->url}' par la méthode HTTP '$mode' a échoué!"; |
trigger_error($e, E_USER_WARNING); |
trigger_error(sprintf("fail: %s \"%s\" (%s)", strtoupper($mode), $this->url, http_build_query($donnees, null, self::HTTP_URL_REQUETE_SEPARATEUR)), |
E_USER_WARNING); |
|
} else { |
// Informations sur les en-têtes et métadonnées du flux |
$this->reponse_entetes = stream_get_meta_data($flux); |