diff --git a/lib/express-csv.js b/lib/express-csv.js index fcc1d69..e0cdfb6 100644 --- a/lib/express-csv.js +++ b/lib/express-csv.js @@ -84,7 +84,7 @@ function objToArray(obj) { /** * Send CSV response with `obj`, optional `headers`, and optional `status`. - * + * * @param {Array} obj * @param {Object|Number} headers or status * @param {Number} status @@ -93,10 +93,16 @@ function objToArray(obj) { */ res.csv = function(obj, headers, status) { + + var page = this.req.route.path.split('/').pop(); + var body = ''; this.charset = this.charset || 'utf-8'; this.header('Content-Type', 'text/csv'); + if(this.get('Content-disposition') == null) + this.header('Content-disposition', 'attachment; filename=' + page + '.csv'); + obj.forEach(function(item) { if (!(item instanceof Array)) item = objToArray(item);