Index: trunk/zoo-project/HISTORY.txt
===================================================================
--- trunk/zoo-project/HISTORY.txt	(revision 382)
+++ trunk/zoo-project/HISTORY.txt	(revision 383)
@@ -12,4 +12,8 @@
   * Add a [headers] section in main.cfg file to add specifics to header returned
   * Add support for multiple outputs for both GET and POST requests
+  * Add Content-Length to the headers if the result is sized
+  * Add Content-Disposition to the headers if the result contains a filename
+  * Add support for sending headers through JS ZOO-api
+  * Add support for multi-valued inputs in JS ZOO-api
 
 Version 1.2.0-rc3
Index: trunk/zoo-project/zoo-api/js/ZOO-api.js
===================================================================
--- trunk/zoo-project/zoo-api/js/ZOO-api.js	(revision 382)
+++ trunk/zoo-project/zoo-api/js/ZOO-api.js	(revision 383)
@@ -6159,5 +6159,9 @@
     var body = new XML('<wps:Execute service="WPS" version="1.0.0" xmlns:wps="'+this.namespaces['wps']+'" xmlns:ows="'+this.namespaces['ows']+'" xmlns:xlink="'+this.namespaces['xlink']+'" xmlns:xsi="'+this.namespaces['xsi']+'" xsi:schemaLocation="'+this.schemaLocation+'"><ows:Identifier>'+this.identifier+'</ows:Identifier>'+this.buildDataInputsNode(inputs)+this.buildDataOutputsNode(outputs)+'</wps:Execute>');
     body = body.toXMLString();
-    var response = ZOO.Request.Post(this.url,body,['Content-Type: text/xml; charset=UTF-8']);
+    var headers=['Content-Type: text/xml; charset=UTF-8'];
+      if(arguments.length>2){
+	headers[headers.length]=arguments[2];
+      }
+    var response = ZOO.Request.Post(this.url,body,headers);
     return response;
   },
@@ -6249,5 +6253,6 @@
      */
     'literal': function(identifier,data) {
-      var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier><wps:Data><wps:LiteralData>'+data.value+'</wps:LiteralData></wps:Data></wps:Input>');
+	if(data && !eval(data["isArray"])){
+	    var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier><wps:Data><wps:LiteralData>'+data.value+'</wps:LiteralData></wps:Data></wps:Input>');
       if (data.type)
         input.*::Data.*::LiteralData.@dataType = data.type;
@@ -6256,4 +6261,17 @@
       input = input.toXMLString();
       return input;
+	}else if(data){
+	    var inputf="";
+	    for(i=0;i<parseInt(data["length"]);i++){
+		var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier><wps:Data><wps:LiteralData>'+data.value[i]+'</wps:LiteralData></wps:Data></wps:Input>');
+		if (data.type)
+		    input.*::Data.*::LiteralData.@dataType = data.type;
+		if (data.uom)
+		    input.*::Data.*::LiteralData.@uom = data.uom;
+		inputf += input.toXMLString();
+	    }
+	    return inputf;
+	}
+	
     }
   },
@@ -6272,7 +6290,7 @@
     for (var attr in inputs) {
       data = inputs[attr];
-      if (data.mimetype || data.type == 'complex')
+	if (data && (data.mimetype || data.type == 'complex'))
         builder = this.buildInput['complex'];
-      else if (data.type == 'reference' || data.type == 'url')
+	else if (data && (data.type == 'reference' || data.type == 'url'))
         builder = this.buildInput['reference'];
       else
Index: trunk/zoo-project/zoo-kernel/service_internal.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal.c	(revision 382)
+++ trunk/zoo-project/zoo-kernel/service_internal.c	(revision 383)
@@ -1745,4 +1745,5 @@
   xmlNodePtr n;
 
+  printHeaders(m);
   doc = xmlNewDoc(BAD_CAST "1.0");
   maps* tmpMap=getMaps(m,"main");
@@ -1899,5 +1900,5 @@
 	  // mimeType information if present here. Maybe we can add more formats
 	  // here.
-	  // If mimeType was not found, we then set txt as the default extension.
+	  // If mimeType was not found, we then set txt as the default extension
 	  map* mtype=getMap(tmpI->content,"mimeType");
 	  if(mtype!=NULL){
@@ -1919,5 +1920,5 @@
 	file_name=(char*)malloc((strlen(tmp1->value)+strlen(s->name)+strlen(ext->value)+strlen(tmpI->name)+13)*sizeof(char));
 	sprintf(file_name,"%s/%s_%s_%i.%s",tmp1->value,s->name,tmpI->name,cpid+100000,ext->value);
-	FILE *ofile=fopen(file_name,"w");
+	FILE *ofile=fopen(file_name,"wb");
 	if(ofile==NULL)
 	  fprintf(stderr,"Unable to create file on disk implying segfault ! \n");
@@ -2000,4 +2001,11 @@
 	  return;
 	}
+	map* fname=getMapFromMaps(tmpI,tmpI->name,"filename");
+	if(fname!=NULL)
+	  printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value);
+	map* rs=getMapFromMaps(tmpI,tmpI->name,"size");
+	if(rs!=NULL)
+	  printf("Content-Length: %s\r\n",rs->value);
+
 	char mime[1024];
 	map* mi=getMap(tmpI->content,"mimeType");
@@ -2020,10 +2028,8 @@
 	    sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
 	printf("%s",mime);
-	if(mi!=NULL && strncmp(mi->value,"image",5)==0){
-	  map* rs=getMapFromMaps(tmpI,tmpI->name,"size");
+	if(rs!=NULL)
 	  fwrite(toto->value,atoi(rs->value),1,stdout);
-	}
 	else
-	  printf("%s",toto->value);
+	  fwrite(toto->value,strlen(toto->value),1,stdout);
 #ifdef DEBUG
 	dumpMap(toto);
Index: trunk/zoo-project/zoo-kernel/service_internal_js.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_js.c	(revision 382)
+++ trunk/zoo-project/zoo-kernel/service_internal_js.c	(revision 383)
@@ -25,4 +25,8 @@
 #include "service_internal.h"
 
+#ifndef JSCLASS_GLOBAL_FLAGS
+#define JSCLSAS_GLOBAL_FLAGS 0
+#endif
+
 static char dbg[1024];
 
@@ -81,5 +85,5 @@
 
   /* The class of the global object. */
-  JSClass global_class = {
+  JSClass global_class= {
     "global", JSCLASS_GLOBAL_FLAGS,
     JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
@@ -99,9 +103,9 @@
   
   /* Create a context. */
-  cx = JS_NewContext(rt,8192);
+  cx = JS_NewContext(rt,81920);
   if (cx == NULL){
     return 1;
   }
-  JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT );//| JSOPTION_METHODJIT);
+  JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT);
   JS_SetVersion(cx, JSVERSION_LATEST);
   JS_SetErrorReporter(cx, reportError);
@@ -111,5 +115,5 @@
   global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL);
   //#else
-  //global = JS_NewObject(cx, &global_class, NULL,NULL);
+  //global = JS_NewObject(cx, &global_class, 0,0);
   //#endif
 
@@ -150,5 +154,5 @@
    * Load the first part of the ZOO-API
    */
-  char *api0=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+16);
+  char *api0=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+17);
   sprintf(api0,"%s/%s/ZOO-proj4js.js",ntmp,tmpm1->value);
 #ifdef JS_DEBUG
@@ -158,5 +162,5 @@
   fflush(stderr);
 
-  char *api1=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+11);
+  char *api1=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+13);
   sprintf(api1,"%s/%s/ZOO-api.js",ntmp,tmpm1->value);
 #ifdef JS_DEBUG
@@ -200,4 +204,5 @@
     exit(-1);
   }
+
   /* Call a function in obj's scope. */
   jsval argv[3];
@@ -264,16 +269,30 @@
     fprintf(stderr," * %d * \n",res);
 #endif
-    jsval tmp2;
-    JSBool hasElement=JS_GetElement(cx,d,1,&tmp2);
-    if(hasElement==JS_TRUE){
-	  freeMaps(outputs);
-	  free(*outputs);
-      *outputs=mapsFromJSObject(cx,tmp2);
-    }
+    if(res==SERVICE_SUCCEEDED){
+      jsval tmp2;
+      JSBool hasElement=JS_GetElement(cx,d,1,&tmp2);
+      if(hasElement==JS_TRUE){
+	freeMaps(outputs);
+	free(*outputs);
+	*outputs=mapsFromJSObject(cx,tmp2);
+      }
+    }else{
+      jsval tmp3;
+      JSBool hasConf=JS_GetElement(cx,d,1,&tmp3);
+      if(hasConf==JS_TRUE){
+	freeMaps(main_conf);
+	free(*main_conf);
+	*main_conf=mapsFromJSObject(cx,tmp3);
+      }
+    }
+
   }
   else{
 #ifdef JS_DEBUG
-    fprintf(stderr,"The serice didn't return an array !\n");
-#endif
+    fprintf(stderr,"The service didn't return an array !\n");
+#endif
+    /**
+     * Extract result
+     */
     jsval tmp1;
     JSBool hasResult=JS_GetProperty(cx,d,"result",&tmp1);
@@ -283,15 +302,39 @@
     fprintf(stderr," * %d * \n",res);
 #endif
+    /**
+     * Extract outputs when available.
+     */
     jsval tmp2;
     JSBool hasElement=JS_GetProperty(cx,d,"outputs",&tmp2);
-#ifdef JS_DEBUG
-    if(!hasElement)
+    if(!JSVAL_IS_VOID(tmp2) && hasElement==JS_TRUE){
+      freeMaps(outputs);
+      free(*outputs);    
+      *outputs=mapsFromJSObject(cx,tmp2);
+    }
+    JS_MaybeGC(cx);
+#ifdef JS_DEBUG
+    if(JSVAL_IS_VOID(tmp2))
       fprintf(stderr,"No outputs property returned\n");
-    if(JS_IsArrayObject(cx,JSVAL_TO_OBJECT(tmp2)))
-      fprintf(stderr,"outputs is array an as expected\n");
-    else
-      fprintf(stderr,"outputs is not an array as expected\n");
-#endif
-    *outputs=mapsFromJSObject(cx,tmp2);
+    else{
+      if(JS_IsArrayObject(cx,JSVAL_TO_OBJECT(tmp2)))
+	fprintf(stderr,"outputs is an array as expected\n");
+      else
+	fprintf(stderr,"outputs is not an array as expected\n");
+    }
+    JS_MaybeGC(cx);
+#endif
+
+    /**
+     * Extract conf when available.
+     */
+    jsval tmp3;
+    JSBool hasConf=JS_GetProperty(cx,d,"conf",&tmp3);
+    if(!JSVAL_IS_VOID(tmp3) && hasConf==JS_TRUE){
+      freeMaps(main_conf);
+      free(*main_conf);
+      *main_conf=mapsFromJSObject(cx,tmp3);
+    }
+    JS_MaybeGC(cx);
+
 #ifdef JS_DEBUG
     dumpMaps(*outputs);
@@ -299,4 +342,5 @@
   }
   /* Cleanup. */
+  JS_MaybeGC(cx);
   JS_DestroyContext(cx);
   JS_DestroyRuntime(rt);
@@ -479,10 +523,8 @@
   jsuint len;
   JSBool hasLen=JS_GetArrayLength(cx, tt, &len);
+#ifdef JS_DEBUG
   if(hasLen==JS_FALSE){
-#ifdef JS_DEBUG
     fprintf(stderr,"outputs array is empty\n");
-#endif
-  }
-#ifdef JS_DEBUG
+  }
   fprintf(stderr,"outputs array length : %d\n",len);
 #endif
@@ -694,4 +736,5 @@
       tmp1=JSValToChar(cx,&tmp);
 #ifdef ULINET_DEBUG
+      curl_easy_setopt(handle.handle,CURLOPT_VERBOSE,1);
       fprintf(stderr,"Element of array n° %d, value : %s\n",i,tmp1);
 #endif
Index: trunk/zoo-project/zoo-kernel/service_internal_js.h
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_js.h	(revision 382)
+++ trunk/zoo-project/zoo-kernel/service_internal_js.h	(revision 383)
@@ -27,5 +27,7 @@
 
 #pragma once 
-
+#ifdef WIN32
+#include <wchar.h>
+#endif
 #include "service.h"
 #include "service_internal.h"
