Skip to content
Myr

Use content-disposition module

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

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 7a7f18c · Browse files · 3 files+17 added−8 removed
This commit

State

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

Diff stats

3 files+17 added−8 removed

  • other:+17 added−8 removed

3 files+17 added−8 removed

modified:lib/response.js+13 added-8 removed
1/**2 * Module dependencies.3 */45var contentDisposition = require('content-disposition');6var deprecate = require('depd')('express');7var escapeHtml = require('escape-html');8var parseUrl = require('parseurl');9var vary = require('vary');
403 unmodified lines
413 * @param {Function} fn414 * @api public415 */416416res.download = function(path, filename, fn){417res.download = function download(path, filename, fn) {418 // support function as second arg418 if ('function' == typeof filename) {419 if (typeof filename === 'function') {420 fn = filename;421 filename = null;422 }423424 filename = filename || path;424 this.set('Content-Disposition', 'attachment; filename="' + basename(filename) + '"');425426 this.set('Content-Disposition', contentDisposition(filename));427428 return this.sendfile(path, fn);429};430431/**
114 unmodified lines
546 * @return {ServerResponse}547 * @api public548 */549547res.attachment = function(filename){548 if (filename) this.type(extname(filename));549 this.set('Content-Disposition', filename550 ? 'attachment; filename="' + basename(filename) + '"'551 : 'attachment');550res.attachment = function attachment(filename) {551 if (filename) {552 this.type(extname(filename));553 }554555 this.set('Content-Disposition', contentDisposition(filename));556557 return this;558};559560/**
274 unmodified lines
modified:History.md+3 added
13.x2===34 * Use `content-disposition` module for `res.attachment`/`res.download`5 - Sends standards-compliant `Content-Disposition` header6 - Full Unicode support7 * deps: connect@2.27.08 - Use `http-errors` module for creating errors9 - Use `utils-merge` module for merging objects10 - deps: body-parser@~1.9.0
1839 unmodified lines
modified:package.json+1 added