+ if ($connect){
+ $streamContext = stream_context_create(array('ssl' => array('verify_peer' => false, 'allow_self_signed' => true)));
+ $f = @stream_socket_client("tcp://$first_host:$port", $nError, $sError, 10, STREAM_CLIENT_CONNECT, $streamContext);
+ spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)","connect");
+ if (!$f) return false;
+ stream_set_timeout($f, 10);
+
+ fputs($f, $connect);
+ fputs($f, "\r\n");
+ $res = fread($f, 1024);
+ if (!$res
+ OR !count($res = explode(' ',$res))
+ OR $res[1]!=='200'){
+ spip_log("Echec CONNECT sur $first_host:$port","connect"._LOG_INFO_IMPORTANTE);
+ fclose($f);
+ return false;
+ }
+ // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
+ stream_set_blocking($f, true);
+ // envoyer le handshake
+ stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
+ spip_log("OK CONNECT sur $first_host:$port","connect");
+ }
+ else {
+ $f = @fsockopen($first_host, $port);
+ spip_log("Recuperer $path sur $first_host:$port par $f");
+ if (!$f) return false;
+ }