From dd35d20a320f9623a9df226536a8797890901595 Mon Sep 17 00:00:00 2001 From: Alexandr Savinykh Date: Tue, 9 Oct 2012 14:35:37 +0400 Subject: [PATCH] Added support for UTF-8 messages content length fixed --- lib/router/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/router/index.js b/lib/router/index.js index ef3f0c5..6188a84 100644 --- a/lib/router/index.js +++ b/lib/router/index.js @@ -33,8 +33,10 @@ router.createServer = function() { res.simpleJSON = function (code, obj) { var body = JSON.stringify(obj); + var m = encodeURIComponent(body).match(/%[89ABab]/g); + res.writeHead(code, [ ["Content-Type", "text/json"] - , ["Content-Length", body.length] + , ["Content-Length", (body.length + (m ? m.length : 0))] ]); res.write(body); res.end();