diff --git a/lib/node/index.js b/lib/node/index.js index 7ce45cdd4..b04db0030 100644 --- a/lib/node/index.js +++ b/lib/node/index.js @@ -156,7 +156,7 @@ function Response(req, res, options) { * - `.contentType` the content type without params * * A response of "Content-Type: text/plain; charset=utf-8" - * will provide you with a `.contentType` of "text/plain". + * will provide you with a `.type` of "text/plain". * * @param {Object} header * @api private diff --git a/lib/superagent.js b/lib/superagent.js index 6e68f1961..3637a5c58 100644 --- a/lib/superagent.js +++ b/lib/superagent.js @@ -203,6 +203,18 @@ var superagent = function(exports){ return fields; } + /** + * Return the mime type for the given `str`. + * + * @param {String} str + * @return {String} + * @api private + */ + + function type(str){ + return str.split(/ *; */).shift(); + }; + /** * Initialize a new `Response` with the given `xhr`. * @@ -265,13 +277,16 @@ var superagent = function(exports){ * - `.contentType` the content type without params * * A response of "Content-Type: text/plain; charset=utf-8" - * will provide you with a `.contentType` of "text/plain". + * will provide you with a `.type` of "text/plain". * * @param {Object} header * @api private */ Response.prototype.setHeaderProperties = function(header){ + var ct = this.header['content-type'] || ''; + this.type = type(ct); + // TODO: moar! var params = (this.header['content-type'] || '').split(/ *; */); this.contentType = params.shift(); diff --git a/test/test.request.js b/test/test.request.js index f9e2a299f..e50bdbe1d 100644 --- a/test/test.request.js +++ b/test/test.request.js @@ -272,11 +272,11 @@ test('POST multiple .send() calls', function(next){ }); }); -test('GET .contentType', function(next){ +test('GET .type', function(next){ request .get('/pets') .end(function(res){ - assert('application/json' == res.contentType); + assert('application/json' == res.type); next(); }); });