[Mapbender-commits] r6846 - in trunk/mapbender/http: classes php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Aug 31 02:41:30 EDT 2010


Author: armin11
Date: 2010-08-31 06:41:29 +0000 (Tue, 31 Aug 2010)
New Revision: 6846

Modified:
   trunk/mapbender/http/classes/class_connector.php
   trunk/mapbender/http/php/mod_layerISOMetadata.php
Log:
Adopt class_connector to disable custom headers definition with post requests. This headers may conflict with upload file by http post which is used for metadata validation of INSPIRE Geoportal. Curl must send its own headers.

Modified: trunk/mapbender/http/classes/class_connector.php
===================================================================
--- trunk/mapbender/http/classes/class_connector.php	2010-08-31 05:42:58 UTC (rev 6845)
+++ trunk/mapbender/http/classes/class_connector.php	2010-08-31 06:41:29 UTC (rev 6846)
@@ -31,8 +31,12 @@
 	private $httpType = "get";
 	private $httpVersion = "1.0";
 	private $httpPostData;
-	private $httpContentType = "text/html";
+	private $httpContentType;
+	private $httpPostFieldsNumber;
+	private $curlSendCustomHeaders = true; //decide to send own headers or not
 		
+
+		
 	/**
 	 * @constructor
 	 * @param String url the URL that will be loaded (optional)
@@ -127,7 +131,15 @@
 			case "httpPostData":
 				$this->httpPostData = $value;
 				break;
-				
+
+			case "httpPostFieldsNumber":
+				$this->httpPostFieldsNumber = $value;
+				break;	
+	
+			case "curlSendCustomHeaders":
+				$this->curlSendHeaders = $value;
+				break;	
+	
 			case "httpContentType":
 				if ($this->isValidHttpContentType($value)) {
 					$this->httpContentType = $value;
@@ -147,7 +159,7 @@
 	}
 	
 	private function isValidHttpContentType ($value) {
-		$validHttpContentTypeArray = array("XML","TEXT/XML");
+		$validHttpContentTypeArray = array("XML","TEXT/XML","APPLICATION/XML","MULTIPART/FORM-DATA");
 		if (in_array(mb_strtoupper($value), $validHttpContentTypeArray)) {
 			switch (mb_strtoupper($value)) {
 				case "XML":
@@ -217,21 +229,28 @@
 		//and set a usefull http header
 		if(strtoupper($this->httpType) == 'POST'){
 			$headers = array(
-					 "POST ".$path." HTTP/1.1",
-            		 "Content-type: ".$this->httpContentType."; charset=".CHARSET,
-           			 "Cache-Control: no-cache",
-	           		 "Pragma: no-cache",
-	           		 "Content-length: ".strlen($this->httpPostData)
+					"POST ".$path." HTTP/1.1",
+            			 	"Content-type: ".$this->httpContentType."; charset=".CHARSET,
+           				"Cache-Control: no-cache",
+	           		 	"Pragma: no-cache",
+	           		 	"Content-length: ".strlen($this->httpPostData)
 			); 
 			$e = new mb_notice("connector: CURL POST: ".$this->httpPostData); 
-			#$e = new mb_exception("connector: CURL POST HEADER: ".print_r($headers));
-			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
-			curl_setopt($ch, CURLOPT_POST, 1);
+			$e = new mb_notice("connector: CURL POST length: ".strlen($this->httpPostData));
+			
+			if ($this->curlSendCustomHeaders) {			
+				curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+			}
+			if ($this->httpPostFieldsNumber != 1){
+				curl_setopt($ch,CURLOPT_POST,$this->httpPostFieldsNumber);
+			} else {
+				curl_setopt($ch, CURLOPT_POST, 1);
+			}
 			curl_setopt($ch, CURLOPT_POSTFIELDS, $this->httpPostData);	
 		}
 		
 		$useragent=CONNECTION_USERAGENT;
-		$e = new mb_notice("connector: CURL connect to: ".$url); 
+		$e = new mb_exception("connector: CURL connect to: ".$url); 
 		curl_setopt ($ch,CURLOPT_USERAGENT,$useragent);
 		$file = curl_exec ($ch);
 		//handle http authentication
@@ -245,7 +264,7 @@
 
 		//reset the env variable http_proxy to the former value
 		putenv("http_proxy=$tmpHttpProxy");	
-		
+		$e = new mb_notice("connector: CURL give back: ".$file);
 		return $file;	
 	}
 

Modified: trunk/mapbender/http/php/mod_layerISOMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_layerISOMetadata.php	2010-08-31 05:42:58 UTC (rev 6845)
+++ trunk/mapbender/http/php/mod_layerISOMetadata.php	2010-08-31 06:41:29 UTC (rev 6846)
@@ -704,6 +704,7 @@
 		//number of post fields:
 		//curl_setopt($ch,CURLOPT_POST,count($fields));
 		$validatorInterfaceObject->set('httpPostFieldsNumber',count($postData));
+		$validatorInterfaceObject->set('curlSendCustomHeaders',false);
 		//$validatorInterfaceObject->set('httpPostData', $postData);
 		$validatorInterfaceObject->set('httpPostData', $postData); #give an array
 		$validatorInterfaceObject->load($validatorUrl);



More information about the Mapbender_commits mailing list