content-disposition
Advanced tools
+10
-0
@@ -0,1 +1,11 @@ | ||
| 0.2.0 / 2014-09-19 | ||
| ================== | ||
| * Reduce ambiguity of file names with hex escape in buggy browsers | ||
| 0.1.2 / 2014-09-19 | ||
| ================== | ||
| * Fix periodic invalid Unicode filename header | ||
| 0.1.1 / 2014-09-19 | ||
@@ -2,0 +12,0 @@ ================== |
+13
-1
@@ -20,2 +20,8 @@ /*! | ||
| /** | ||
| * RegExp to match US-ASCII string | ||
| */ | ||
| var asciiStringRegExp = /^[\x00-\x7f]*$/ | ||
| /** | ||
| * RegExp to match non attr-char, *after* encodeURIComponent (i.e. not including "%") | ||
@@ -27,2 +33,8 @@ */ | ||
| /** | ||
| * RegExp to match percent encoding escape. | ||
| */ | ||
| var hexEscapeRegExp = /%[0-9A-F]{2}/i | ||
| /** | ||
| * RegExp to match non-US-ASCII characters. | ||
@@ -67,3 +79,3 @@ */ | ||
| if (!nonAsciiRegExp.test(name)) { | ||
| if (asciiStringRegExp.test(name) && !hexEscapeRegExp.test(name)) { | ||
| // simple header | ||
@@ -70,0 +82,0 @@ // file name is always quoted and not a token for RFC 2616 compatibility |
+1
-1
| { | ||
| "name": "content-disposition", | ||
| "description": "Create an attachment Content-Disposition header", | ||
| "version": "0.1.1", | ||
| "version": "0.2.0", | ||
| "contributors": [ | ||
@@ -6,0 +6,0 @@ "Douglas Christopher Wilson <doug@somethingdoug.com>" |
+26
-0
@@ -32,2 +32,28 @@ # content-disposition | ||
| ## Examples | ||
| ### Send a file for download | ||
| ```js | ||
| var contentDisposition = require('content-disposition') | ||
| var destroy = require('destroy') | ||
| var http = require('http') | ||
| var onFinished = require('on-finished') | ||
| var filePath = '/path/to/public/plans.pdf' | ||
| http.createServer(function onRequest(req, res) { | ||
| // set headers | ||
| res.setHeader('Content-Type', 'application/pdf') | ||
| res.setHeader('Content-Disposition', contentDisposition(filePath)) | ||
| // send file | ||
| var stream = fs.createReadStream(filePath) | ||
| stream.pipe(res) | ||
| onFinished(res, function (err) { | ||
| destroy(stream) | ||
| }) | ||
| }) | ||
| ``` | ||
| ## Testing | ||
@@ -34,0 +60,0 @@ |
7758
14.68%109
7.92%90
40.63%