Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,31 @@ Response.prototype.link = function link(l, rel) {
* @returns {Object} self, the response object
*/
Response.prototype.send = function send(code, body, headers) {
return this.__send(code, body, headers, true);
};

/**
* sends the response object as-is without formatting. convenience method that
* handles: writeHead(), write(), end()
* @public
* @function send
* @param {Number} code http status code
* @param {Object | Buffer | Error} body the content to send
* @param {Object} headers any add'l headers to set
* @returns {Object} self, the response object
*/
Response.prototype.sendRaw = function sendRaw(code, body, headers) {
return this.__send(code, body, headers, false);
};

Response.prototype.__send = function __send(code, body, headers, format) {
var isHead = (this.req.method === 'HEAD');
var log = this.log;
var self = this;

if (code === undefined) {
this.statusCode = 200;
} else if (code.constructor.name === 'Number') {
} else if (typeof code === 'number') {
this.statusCode = code;

if (body instanceof Error) {
Expand Down Expand Up @@ -316,7 +334,7 @@ Response.prototype.send = function send(code, body, headers) {
// know at this point what format to send the error as. Additionally,
// the current 'after' event is emitted _before_ we send the response,
// so there's no way to re-emit the error here. TODO: clean up 'after'
// even emitter so we pick up the error here.
// event emitter so we pick up the error here.
if (err) {
self._data = null;
self.statusCode = 500;
Expand All @@ -341,10 +359,12 @@ Response.prototype.send = function send(code, body, headers) {
}
}

if (body !== undefined) {
if (body === undefined) {
_cb(null, null);
} else if (format) {
this.format(body, _cb);
} else {
_cb(null, null);
_cb(null, body);
}

return (this);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"name": "restify",
"homepage": "http://restifyjs.com",
"description": "REST framework",
"version": "4.3.4",
"version": "4.3.5",
"repository": {
"type": "git",
"url": "git://github.com/restify/node-restify.git"
Expand Down