From 6141bfac4b4ec93702732a1f2d63a9c0e4b42d8e Mon Sep 17 00:00:00 2001 From: orls Date: Wed, 15 Jun 2011 13:55:59 +0100 Subject: [PATCH 1/2] Correctly overwrite any existing content-length / content-type headers --- lib/connect-jsonp.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/connect-jsonp.js b/lib/connect-jsonp.js index cbd82cd..89b6bab 100644 --- a/lib/connect-jsonp.js +++ b/lib/connect-jsonp.js @@ -94,8 +94,8 @@ module.exports = function jsonp(config) { res.end = function(data, encoding) { if (data) body += data; body = context.callback + '(' + body + ')'; - res.setHeader('Content-Type', APP_JS_CONTENT_TYPE); - res.setHeader('Content-Length', body.length); + headers['Content-Type'] = APP_JS_CONTENT_TYPE; + headers['Content-Length'] = body.length; previous(code, headers, res, context, body, encoding); }; From 4fe8c6de73ed7e27f25ef8f1553c9a791e5e9224 Mon Sep 17 00:00:00 2001 From: orls Date: Wed, 15 Jun 2011 13:57:04 +0100 Subject: [PATCH 2/2] Write byte-length instead of string length, defaulting to UTF8 --- lib/connect-jsonp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/connect-jsonp.js b/lib/connect-jsonp.js index 89b6bab..63b3146 100644 --- a/lib/connect-jsonp.js +++ b/lib/connect-jsonp.js @@ -95,7 +95,7 @@ module.exports = function jsonp(config) { if (data) body += data; body = context.callback + '(' + body + ')'; headers['Content-Type'] = APP_JS_CONTENT_TYPE; - headers['Content-Length'] = body.length; + headers['Content-Length'] = Buffer.byteLength(body, encoding || "utf8"); previous(code, headers, res, context, body, encoding); };