Skip to content

Commit

Permalink
Fixed wrong content length when the content contains special characte…
Browse files Browse the repository at this point in the history
…rs + Specified the encoding when writing to the response body (UTF-8) + Minimified the 'Content-Type' header in the 'writeBody' method of the 'RequestContext' class
  • Loading branch information
AdrienCastex committed Jul 31, 2017
1 parent 014820b commit c12096a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions lib/server/v2/RequestContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/server/v2/RequestContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit c12096a

Please sign in to comment.