Index: json_server.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/json_server/json_server.module,v
retrieving revision 1.8
diff -u -p -r1.8 json_server.module
--- json_server.module	13 Jan 2008 16:00:59 -0000	1.8
+++ json_server.module	29 Oct 2008 17:38:58 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: json_server.module,v 1.8 2008/01/13 16:00:59 dmitrig01 Exp $
+// $Id: json_server.module,v 1.8.2.1 2008/01/13 16:12:23 dmitrig01 Exp $
 
 function json_server_server_info() {
   return array(
@@ -30,25 +30,60 @@ function json_server_server() {
           $args[] = $_POST[$arg['#name']];
         }
         elseif($arg['#optional'] == 0) {
-          return drupal_to_js(array("status" => FALSE, "data" => "Argument ". $arg['#name'] ." not recieved"));
+          return json_server_to_js(array("status" => FALSE, "data" => "Argument ". $arg['#name'] ." not recieved"));
         }
         else {
           $args[] = NULL;
         }
       }
+
       $result = services_method_call($method['#method'], $args);
       if (is_array($result) && isset($result['#error']) && $result['#error'] === TRUE)
-        return drupal_to_js(array('status' => FALSE, 'data' => $result['#message']));
+        return json_server_to_js(array('status' => FALSE, 'data' => $result['#message']));
       
-      return drupal_to_js(array('status' => TRUE, 'data' => $result));
+      return json_server_to_js(array('status' => TRUE, 'data' => $result));
     }
   }
 
-  return drupal_to_js(array('status' => FALSE, 'data' => "Invalid method $request"));
+  return json_server_to_js(array('status' => FALSE, 'data' => "Invalid method $request"));
 }
 
 function json_load() {
   global $base_url;
   $path = drupal_get_path("module", "json_server");
   drupal_add_js($path ."/json_server.js");
-}
\ No newline at end of file
+  drupal_add_js(array('basePath' => base_path()), 'setting');
+}
+
+function json_server_to_js($contents) {
+  if (function_exists("json_encode"))
+    $contents = json_encode($contents);
+  else
+    $contents = drupal_to_js($contents);
+
+  global $HTTP_ACCEPT_ENCODING;
+  if (headers_sent()){
+    $encoding = false;
+  }
+  elseif (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false){
+      $encoding = 'x-gzip';
+  }
+  elseif( strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false){
+    $encoding = 'gzip';
+  }
+  else {
+    $encoding = false;
+  }
+    
+  if ($encoding){
+    header('Content-Encoding: '. $encoding);
+    print "\x1f\x8b\x08\x00\x00\x00\x00\x00";
+    $size = strlen($contents);
+    $contents = gzcompress($contents, 9);
+    $contents = substr($contents, 0, $size);
+    return $contents;
+  }
+  else {
+    return $contents;
+  }
+}
