res.attachment.js
This file
Path
test/res.attachment.js
119 lines · 2.9 KiB · JavaScript
Last changed by
Upgrade `content-disposition` (#7233)Blake Embreybefore adoption59e205a
History of this fileTake it
The walk stopped after 200 commits: lines older than 2027b87 point at it.
fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87
lines 1–2why, one step back1'use strict'2chore: enforce explicit Buffer import and add lint rule (#6525)Shivam Sharmabefore adoption98c85eb
lines 3–4why, one step back3const { Buffer } = require('node:buffer');4fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87
lines 5–33why, one step back5var express = require('../')6 , request = require('supertest');78describe('res', function(){9 describe('.attachment()', function(){10 it('should Content-Disposition to attachment', function(done){11 var app = express();1213 app.use(function(req, res){14 res.attachment().send('foo');15 });1617 request(app)18 .get('/')19 .expect('Content-Disposition', 'attachment', done);20 })21 })2223 describe('.attachment(filename)', function(){24 it('should add the filename param', function(done){25 var app = express();2627 app.use(function(req, res){28 res.attachment('/path/to/image.png');29 res.send('foo');30 });3132 request(app)33 .get('/')Upgrade `content-disposition` (#7233)Blake Embreybefore adoption59e205a
line 34why, one step back34 .expect('Content-Disposition', 'attachment; filename=image.png', done);fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87
lines 35–36why, one step back35 })36Upgrade `content-disposition` (#7233)Blake Embreybefore adoption59e205a
lines 37–62why, one step back37 it('should quote file names that are not a valid token', function(done){38 var app = express();3940 app.use(function(req, res){41 res.attachment('/path/to/my report.png');42 res.send('foo');43 });4445 request(app)46 .get('/')47 .expect('Content-Disposition', 'attachment; filename="my report.png"', done);48 })4950 it('should handle an empty file name', function(done){51 var app = express();5253 app.use(function(req, res){54 res.attachment('');55 res.send('foo');56 });5758 request(app)59 .get('/')60 .expect('Content-Disposition', 'attachment; filename=""', done);61 })62fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87
lines 63–88why, one step back63 it('should set the Content-Type', function(done){64 var app = express();6566 app.use(function(req, res){67 res.attachment('/path/to/image.png');68 res.send(Buffer.alloc(4, '.'))69 });7071 request(app)72 .get('/')73 .expect('Content-Type', 'image/png', done);74 })75 })7677 describe('.attachment(utf8filename)', function(){78 it('should add the filename and filename* params', function(done){79 var app = express();8081 app.use(function(req, res){82 res.attachment('/locales/日本語.txt');83 res.send('japanese');84 });8586 request(app)87 .get('/')88 .expect('Content-Disposition', 'attachment; filename="???.txt"; filename*=UTF-8\'\'%E6%97%A5%E6%9C%AC%E8%AA%9E.txt')Upgrade `content-disposition` (#7233)Blake Embreybefore adoption59e205a
lines 89–102why, one step back89 .expect(200, done);90 })9192 it('should encode latin1 file names with an ASCII fallback and filename* param', function(done){93 var app = express();9495 app.use(function(req, res){96 res.attachment('/locales/café.txt');97 res.send('coffee');98 });99100 request(app)101 .get('/')102 .expect('Content-Disposition', 'attachment; filename="caf?.txt"; filename*=UTF-8\'\'caf%C3%A9.txt')fix(deps): cookie@0.7.0Josh Bukerbefore adoption2027b87
lines 103–119why, one step back103 .expect(200, done);104 })105106 it('should set the Content-Type', function(done){107 var app = express();108109 app.use(function(req, res){110 res.attachment('/locales/日本語.txt');111 res.send('japanese');112 });113114 request(app)115 .get('/')116 .expect('Content-Type', 'text/plain; charset=utf-8', done);117 })118 })119})