Skip to content

Commit

Permalink
Merge branch 'remove-header-fields'
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jul 15, 2011
2 parents 986916c + 365b3a7 commit 772c135
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 194 deletions.
37 changes: 10 additions & 27 deletions lib/response.js
Expand Up @@ -22,31 +22,23 @@ var fs = require('fs')
, join = path.join;

/**
* Send a response with the given `body` and optional `headers` and `status` code.
* Send a response with the given `body` and optional `status` code.
*
* Examples:
*
* res.send(new Buffer('wahoo'));
* res.send({ some: 'json' });
* res.send('<p>some html</p>');
* res.send('Sorry, cant find that', 404);
* res.send('text', { 'Content-Type': 'text/plain' }, 201);
* res.send(404);
*
* @param {String|Object|Number|Buffer} body or status
* @param {Object|Number} headers or status
* @param {Number} status
* @return {ServerResponse}
* @api public
*/

res.send = function(body, headers, status){
// allow status as second arg
if ('number' == typeof headers) {
status = headers,
headers = null;
}

res.send = function(body, status){
// default status
status = status || this.statusCode;

Expand All @@ -71,7 +63,7 @@ res.send = function(body, headers, status){
this.contentType('.bin');
}
} else {
return this.json(body, headers, status);
return this.json(body, status);
}
break;
}
Expand All @@ -83,15 +75,6 @@ res.send = function(body, headers, status){
: Buffer.byteLength(body));
}

// merge headers passed
if (headers) {
var fields = Object.keys(headers);
for (var i = 0, len = fields.length; i < len; ++i) {
var field = fields[i];
this.header(field, headers[field]);
}
}

// strip irrelevant headers
if (204 == status || 304 == status) {
this.removeHeader('Content-Type');
Expand All @@ -105,7 +88,7 @@ res.send = function(body, headers, status){
};

/**
* Send JSON response with `obj`, optional `headers`, and optional `status`.
* Send JSON response with `obj` and optional `status`.
*
* Examples:
*
Expand All @@ -115,13 +98,13 @@ res.send = function(body, headers, status){
* res.json('I dont have that', 404);
*
* @param {Mixed} obj
* @param {Object|Number} headers or status
* @param {Number} status
* @param {Number} status
* @return {ServerResponse}
* @api public
*/

res.json = function(obj, headers, status){
res.json = function(obj, status){
var body = JSON.stringify(obj)
, callback = this.req.query.callback
, jsonp = this.app.enabled('jsonp callback');
Expand All @@ -134,7 +117,7 @@ res.json = function(obj, headers, status){
body = callback.replace(/[^\w$.]/g, '') + '(' + body + ');';
}

return this.send(body, headers, status);
return this.send(body, status);
};

/**
Expand Down Expand Up @@ -266,16 +249,16 @@ res.download = function(path, filename, fn, fn2){
*
* @param {String} name
* @param {String} val
* @return {String}
* @return {ServerResponse} for chaining
* @api public
*/

res.header = function(name, val){
if (val === undefined) {
if (1 == arguments.length) {
return this.getHeader(name);
} else {
this.setHeader(name, val);
return val;
return this;
}
};

Expand Down
2 changes: 1 addition & 1 deletion lib/router/index.js
Expand Up @@ -266,7 +266,7 @@ Router.prototype._dispatch = function(req, res, next){
Router.prototype._options = function(req, res){
var path = parse(req.url).pathname
, body = this._optionsFor(path).join(',');
res.send(body, { Allow: body });
res.header('Allow', body).send(body);
};

/**
Expand Down

0 comments on commit 772c135

Please sign in to comment.