diff --git a/ecrire/inc/distant.php b/ecrire/inc/distant.php
index 2e4b541df17932cad4ee3ba53eefb61d1953d64b..58a44adda922ca07326509664bfaf0b457ef82ae 100644
--- a/ecrire/inc/distant.php
+++ b/ecrire/inc/distant.php
@@ -1236,16 +1236,37 @@ function need_proxy($host, $http_proxy = null, $http_noproxy = null) {
 	if (is_null($http_proxy)) {
 		$http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null;
 	}
+	// rien a faire si pas de proxy :)
+	if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
+		return '';
+	}
+
 	if (is_null($http_noproxy)) {
 		$http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null;
 	}
+	// si pas d'exception, on retourne le proxy
+	if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
+		return $http_proxy;
+	}
+
+	// si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
+	// $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
+	$http_noproxy = str_replace("\n", " ", $http_noproxy);
+	$http_noproxy = str_replace("\r", " ", $http_noproxy);
+	$http_noproxy = " $http_noproxy ";
+	$domain = $host;
+	do {
+		if (strpos($http_noproxy, " $domain ") !== false) {
+			return '';
+		}
 
-	$domain = substr($host, strpos($host, '.'));
+		$domain = explode('.', $domain);
+		array_shift($domain);
+		$domain = implode('.', $domain);
+	} while (strpos($domain, '.') !== false);
 
-	return ($http_proxy
-		and (strpos(" $http_noproxy ", " $host ") === false
-			and (strpos(" $http_noproxy ", " $domain ") === false)))
-		? $http_proxy : '';
+	// ok c'est pas une exception
+	return $http_proxy;
 }