From c12096a04f71559064746c18f7289168656d2708 Mon Sep 17 00:00:00 2001 From: Adrien Castex Date: Mon, 31 Jul 2017 17:15:19 +0200 Subject: [PATCH] Fixed wrong content length when the content contains special characters + Specified the encoding when writing to the response body (UTF-8) + Minimified the 'Content-Type' header in the 'writeBody' method of the 'RequestContext' class --- lib/server/v2/RequestContext.js | 12 ++++++------ src/server/v2/RequestContext.ts | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/server/v2/RequestContext.js b/lib/server/v2/RequestContext.js index cc4d238a..2f9e96fc 100644 --- a/lib/server/v2/RequestContext.js +++ b/lib/server/v2/RequestContext.js @@ -238,15 +238,15 @@ var HTTPRequestContext = (function (_super) { switch (this.headers.findBestAccept()) { default: case 'xml': - this.response.setHeader('Content-Type', 'application/xml; charset="utf-8"'); - this.response.setHeader('Content-Length', content.length.toString()); - this.response.write(content); + this.response.setHeader('Content-Type', 'application/xml;charset=utf-8'); + this.response.setHeader('Content-Length', new Buffer(content).length.toString()); + this.response.write(content, 'UTF-8'); break; case 'json': content = xml_js_builder_1.XML.toJSON(content); - this.response.setHeader('Content-Type', 'application/json; charset="utf-8"'); - this.response.setHeader('Content-Length', content.length.toString()); - this.response.write(content); + this.response.setHeader('Content-Type', 'application/json;charset=utf-8'); + this.response.setHeader('Content-Length', new Buffer(content).length.toString()); + this.response.write(content, 'UTF-8'); break; } this.responseBody = content; diff --git a/src/server/v2/RequestContext.ts b/src/server/v2/RequestContext.ts index 37375aab..2021b350 100644 --- a/src/server/v2/RequestContext.ts +++ b/src/server/v2/RequestContext.ts @@ -332,16 +332,16 @@ export class HTTPRequestContext extends RequestContext { default: case 'xml': - this.response.setHeader('Content-Type', 'application/xml; charset="utf-8"'); - this.response.setHeader('Content-Length', content.length.toString()); - this.response.write(content); + this.response.setHeader('Content-Type', 'application/xml;charset=utf-8'); + this.response.setHeader('Content-Length', new Buffer(content).length.toString()); + this.response.write(content, 'UTF-8'); break; case 'json': content = XML.toJSON(content); - this.response.setHeader('Content-Type', 'application/json; charset="utf-8"'); - this.response.setHeader('Content-Length', content.length.toString()); - this.response.write(content); + this.response.setHeader('Content-Type', 'application/json;charset=utf-8'); + this.response.setHeader('Content-Length', new Buffer(content).length.toString()); + this.response.write(content, 'UTF-8'); break; }