res.attachment.js
This file
Path
test/res.attachment.js
76 lines · 1.8 KiB · JavaScript
Last changed by
Use content-disposition moduleDouglas Christopher Wilsonbefore adoption6f31218
History of this fileTake it
The walk stopped after 200 commits: lines older than 6bc7574 point at it.
docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 1–58why, one step back12var express = require('../')3 , request = require('supertest');45describe('res', function(){6 describe('.attachment()', function(){7 it('should Content-Disposition to attachment', function(done){8 var app = express();910 app.use(function(req, res){11 res.attachment().send('foo');12 });1314 request(app)15 .get('/')16 .expect('Content-Disposition', 'attachment', done);17 })18 })1920 describe('.attachment(filename)', function(){21 it('should add the filename param', function(done){22 var app = express();2324 app.use(function(req, res){25 res.attachment('/path/to/image.png');26 res.send('foo');27 });2829 request(app)30 .get('/')31 .expect('Content-Disposition', 'attachment; filename="image.png"', done);32 })3334 it('should set the Content-Type', function(done){35 var app = express();3637 app.use(function(req, res){38 res.attachment('/path/to/image.png');39 res.send(new Buffer(4));40 });4142 request(app)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('/')Use content-disposition moduleDouglas Christopher Wilsonbefore adoption6f31218
lines 59–60why, one step back59 .expect('Content-Disposition', 'attachment; filename="???.txt"; filename*=UTF-8\'\'%E6%97%A5%E6%9C%AC%E8%AA%9E.txt')60 .expect(200, done);docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574
lines 61–76why, one step back61 })6263 it('should set the Content-Type', function(done){64 var app = express();6566 app.use(function(req, res){67 res.attachment('/locales/日本語.txt');68 res.send('japanese');69 });7071 request(app)72 .get('/')73 .expect('Content-Type', 'text/plain; charset=utf-8', done);74 })75 })76})