Skip to content

Commit e0bc571

Browse files
aheckmanntj
authored andcommitted
auto set Content-Type in res.attachement
Signed-off-by: Tj Holowaychuk <[email protected]>
1 parent 957cf45 commit e0bc571

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/response.js

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ res.contentType = function(type){
176176
*/
177177

178178
res.attachment = function(filename){
179+
if (filename) this.contentType(filename);
179180
this.header('Content-Disposition', filename
180181
? 'attachment; filename="' + path.basename(filename) + '"'
181182
: 'attachment');

test/response.test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,14 @@ module.exports = {
207207
assert.response(app,
208208
{ url: '/javascripts/jquery.js' },
209209
{ body: 'whatever'
210-
, headers: { 'Content-Disposition': 'attachment; filename="jquery.js"' }});
210+
, headers: { 'Content-Type': 'application/javascript'
211+
, 'Content-Disposition': 'attachment; filename="jquery.js"' }});
211212

212213
assert.response(app,
213214
{ url: '/style.css' },
214215
{ body: 'some stylezzz'
215-
, headers: { 'Content-Disposition': 'attachment' }});
216+
, headers: { 'Content-Type': 'text/html; charset=utf-8'
217+
, 'Content-Disposition': 'attachment' }});
216218
},
217219

218220
'test #redirect()': function(){

0 commit comments

Comments
 (0)