[Groonga-commit] groonga/gcs [master] Set correct content-length

Back to archive index

YUKI Hiroshi null+****@clear*****
Mon Oct 22 11:41:50 JST 2012


YUKI Hiroshi	2012-10-22 11:41:50 +0900 (Mon, 22 Oct 2012)

  New Revision: 2fcd7bdb0ead30f9571f075df4f2f514a4977a1c
  https://github.com/groonga/gcs/commit/2fcd7bdb0ead30f9571f075df4f2f514a4977a1c

  Log:
    Set correct content-length

  Modified files:
    lib/client.js

  Modified: lib/client.js (+8 -1)
===================================================================
--- lib/client.js    2012-10-22 11:25:15 +0900 (5bda8bf)
+++ lib/client.js    2012-10-22 11:41:50 +0900 (d39e93e)
@@ -85,10 +85,17 @@ Client.prototype = {
     };
     service.addCommonOptions = function(options, args) {
       options.headers['content-type'] = 'application/json';
-      options.headers['content-length'] = JSON.stringify(args.Docs).length;
+      options.headers['content-length'] = this.countBytes(JSON.stringify(args.Docs));
     };
     return service;
   },
+  countBytes: function(string) {
+    string = encodeURIComponent(string);
+    var escapedPartsMatcher = /\%[0-9a-f][0-9a-f]/gi;
+    var escapedParts = string.match(escapedPartsMatcher);
+    var notEscapedParts = string.replace(escapedPartsMatcher, '');
+    return notEscapedParts.length + (escapedParts ? escapedParts.length : 0);
+  },
   get documentsAPI() {
     return this._documentsAPI;
   },
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index