Skip to content
Myr

support non-ascii filenames in content-disposition headers

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Andy VanWagoner · committed by Andy VanWagoner · parent 79cc5a4 · Browse files · 5 files+60 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+60 added−5 removed

  • tests:+31 added−0 removed
  • other:+29 added−5 removed

5 files+60 added−5 removed

added:examples/downloads/files/utf-8 한中日.txt+1 added
1한中日
modified:examples/downloads/app.js+2 added-1 removed
modified:lib/response.js+3 added-4 removed
7 unmodified lines
8var escapeHtml = require('escape-html');9var sign = require('cookie-signature').sign;10var normalizeType = require('./utils').normalizeType;11var normalizeTypes = require('./utils').normalizeTypes;12var contentDisposition = require('./utils').contentDisposition;13var etag = require('./utils').etag;14var statusCodes = http.STATUS_CODES;15var cookie = require('cookie');16var send = require('send');
348 unmodified lines
365 filename = null;366 }367368 filename = filename || path;368 this.set('Content-Disposition', 'attachment; filename="' + basename(filename) + '"');369 this.set('Content-Disposition', contentDisposition(filename));370 return this.sendfile(path, fn);371};372373/**
113 unmodified lines
487 */488489res.attachment = function(filename){490 if (filename) this.type(extname(filename));490 this.set('Content-Disposition', filename491 ? 'attachment; filename="' + basename(filename) + '"'492 : 'attachment');491 this.set('Content-Disposition', contentDisposition(filename));492 return this;493};494495/**
282 unmodified lines
modified:lib/utils.js+23 added
modified:test/res.attachment.js+31 added
42 unmodified lines
43 .get('/')44 .expect('Content-Type', 'image/png', done);45 })46 })4748 describe('.attachment(utf8filename)', function(){49 it('should add the filename and filename* params', function(done){50 var app = express();5152 app.use(function(req, res){53 res.attachment('/locales/日本語.txt');54 res.send('japanese');55 });5657 request(app)58 .get('/')59 .expect('Content-Disposition', 'attachment;' +60 ' filename=%E6%97%A5%E6%9C%AC%E8%AA%9E.txt;' +61 ' filename*=UTF-8\'\'%E6%97%A5%E6%9C%AC%E8%AA%9E.txt',62 done);63 })6465 it('should set the Content-Type', function(done){66 var app = express();6768 app.use(function(req, res){69 res.attachment('/locales/日本語.txt');70 res.send('japanese');71 });7273 request(app)74 .get('/')75 .expect('Content-Type', 'text/plain; charset=utf-8', done);76 })77 })78})