Socket
Socket
Sign inDemoInstall

content-disposition

Package Overview
Dependencies
0
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.1 to 0.2.0

10

HISTORY.md

@@ -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 @@ ==================

14

index.js

@@ -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

2

package.json
{
"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>"

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc