{"name":"content-disposition","version":"1.1.0","keywords":["content-disposition","http","rfc6266","res"],"author":{"name":"Douglas Christopher Wilson","email":"doug@somethingdoug.com"},"license":"MIT","_id":"content-disposition@1.1.0","maintainers":[{"name":"ulisesgascon","email":"ulisesgascondev@gmail.com"},{"name":"blakeembrey","email":"hello@blakeembrey.com"},{"name":"wesleytodd","email":"wes@wesleytodd.com"},{"name":"dougwilson","email":"doug@somethingdoug.com"}],"homepage":"https://github.com/jshttp/content-disposition#readme","bugs":{"url":"https://github.com/jshttp/content-disposition/issues"},"dist":{"shasum":"f3db789c752d45564cc7e9e1e0b31790d4a38e17","tarball":"http://registry-npm.ywwl.com/content-disposition/download/content-disposition-1.1.0.tgz","fileCount":4,"integrity":"sha512-5jRCH9Z/+DRP7rkvY83B+yGIGX96OYdJmzngqnw2SBSxqCFPd0w2km3s5iawpGX8krnwSGmF0FW5Nhr0Hfai3g==","signatures":[{"sig":"MEUCIQDexFUaDbi91ciSC71itohsS6u05ESCTDppxQRQWJhUoQIgT0sBd9oCzA7EfZCZP7y5ewsza2NJjFaqq8zk3CwOUks=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":19928,"size":7066,"noattachment":false,"key":"/content-disposition/-/content-disposition-1.1.0.tgz"},"engines":{"node":">=18"},"funding":{"url":"https://opencollective.com/express","type":"opencollective"},"gitHead":"9c42e50a0de8f7afc17c788e3ede99fee1b213cc","scripts":{"lint":"eslint .","test":"node --test --test-reporter spec","test-ci":"c8 --reporter=lcovonly --reporter=text npm test","test-cov":"c8 --reporter=html --reporter=text npm test"},"_npmUser":{"name":"blakeembrey","email":"hello@blakeembrey.com"},"repository":{"url":"git+https://github.com/jshttp/content-disposition.git","type":"git"},"_npmVersion":"11.12.1","description":"Create and parse Content-Disposition header","directories":{},"_nodeVersion":"25.9.0","_hasShrinkwrap":false,"devDependencies":{"c8":"^10.1.2","eslint":"^8.57.1","eslint-plugin-node":"^11.1.0","eslint-plugin-import":"^2.32.0","eslint-plugin-promise":"^6.6.0","eslint-config-standard":"^14.1.1","eslint-plugin-markdown":"^3.0.1","eslint-plugin-standard":"^4.1.0"},"_npmOperationalInternal":{"tmp":"tmp/content-disposition_1.1.0_1775596073614_0.8745281295056331","host":"s3://npm-registry-packages-npm-production"},"readme":"# content-disposition\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Node.js Version][node-version-image]][node-version-url]\n[![Build Status][github-actions-ci-image]][github-actions-ci-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n\nCreate and parse HTTP `Content-Disposition` header\n\n## Installation\n\n```sh\n$ npm install content-disposition\n```\n\n## API\n\n```js\nimport { create, parse, format } from 'content-disposition';\n```\n\n### create(filename, options)\n\nCreate an attachment `Content-Disposition` header value using the given file name,\nif supplied. The `filename` is optional and if no file name is desired, but you\nwant to specify `options`, set `filename` to `undefined`.\n\n```js\nres.setHeader('Content-Disposition', create('∫ maths.pdf'));\n```\n\n**note** HTTP headers are of the ISO-8859-1 character set. If you are writing this\nheader through a means different from `setHeader` in Node.js, you'll want to specify\nthe `'binary'` encoding in Node.js.\n\n#### Options\n\n`contentDisposition` accepts these properties in the options object.\n\n##### fallback\n\nIf the `filename` option is outside US-ASCII, then the file name is actually\nstored in a supplemental field for clients that support Unicode file names and\na US-ASCII version of the file name is automatically generated.\n\nThis specifies the US-ASCII file name to override the automatic generation or\ndisables the generation all together, defaults to `true`.\n\n- A string will specify the US-ASCII file name to use in place of automatic\n  generation.\n- `false` will disable including a US-ASCII file name and only include the\n  Unicode version (unless the file name is already US-ASCII).\n- `true` will enable automatic generation if the file name is outside US-ASCII.\n\nIf the `filename` option is US-ASCII and this option is specified and has a\ndifferent value, then the `filename` option is encoded in the extended field\nand this set as the fallback field, even though they are both US-ASCII.\n\n##### type\n\nSpecifies the disposition type, defaults to `\"attachment\"`. This can also be\n`\"inline\"`, or any other value (all values except inline are treated like\n`attachment`, but can convey additional information if both parties agree to\nit).\n\n### parse(string, options)\n\n```js\nconst disposition = parse(\n  'attachment; filename=\"EURO rates.txt\"; filename*=UTF-8\\'\\'%e2%82%ac%20rates.txt',\n);\n```\n\nParse a `Content-Disposition` header string. This automatically handles extended\n(\"Unicode\") parameters by decoding them and providing them under the standard\nparameter name. This will return an object with the following properties:\n\n- `type`: The disposition type (always lower case). Example: `'attachment'`\n\n- `parameters`: An object of the parameters in the disposition (name of parameter\n  always lower case and extended versions replace non-extended versions). Example:\n  `{filename: \"€ rates.txt\"}`\n\n#### Options\n\n##### multipart\n\nParse parameters using browser `multipart/form-data` behavior.\n\n```js\nparse('form-data; name=\"file\"; filename=\"the %22plans%22.pdf\"', {\n  multipart: true,\n});\n```\n\n##### extended\n\nParse RFC 5987 extended header parameters automatically when decoding\nparameters, defaults to `true`.\n\n### format(obj, options)\n\n```js\nconst disposition = format({\n  type: 'attachment',\n  parameters: {\n    filename: '€ rates.txt',\n  },\n});\n```\n\nFormats an object to a `Content-Disposition` header string. This automatically\nhandles extended (\"Unicode\") parameters and returns a string. Example:\n`'attachment; filename*=UTF-8''%E2%82%AC%20rates.txt'`\n\n#### Options\n\n##### multipart\n\nFormat parameters using browser `multipart/form-data` behavior. This quotes\nparameter values, escapes `\"` as `%22`, and writes Unicode values directly\ninstead of using extended parameters.\n\n```js\nformat(\n  {\n    type: 'form-data',\n    parameters: { name: 'file', filename: '€ rates.txt' },\n  },\n  { multipart: true },\n);\n```\n\n##### extended\n\nEncode Unicode parameter values using RFC 5987 extended header parameters,\ne.g. `filename*=`, defaults to `true`.\n\n## Examples\n\n### Send a file for download\n\n```js\nimport fs from 'node:fs';\nimport http from 'node:http';\nimport { create } from 'content-disposition';\nimport onFinished from 'on-finished';\n\nconst filePath = '/path/to/public/plans.pdf';\n\nhttp.createServer(function onRequest(req, res) {\n  // set headers\n  res.setHeader('Content-Type', 'application/pdf');\n  res.setHeader('Content-Disposition', create(filePath));\n\n  // send file\n  const stream = fs.createReadStream(filePath);\n  stream.pipe(res);\n  onFinished(res, function () {\n    stream.destroy();\n  });\n});\n```\n\n## Local demo\n\nRun the upload inspector locally:\n\n```sh\nnpm run demo\n```\n\nThen open `http://127.0.0.1:3000` in your browser. The demo lets you upload files, inspect the multipart upload part headers sent by the browser, and compare them with the download `Content-Disposition` header generated by this package.\n\n## Testing\n\n```sh\n$ npm test\n```\n\n## References\n\n- [RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1][rfc-2616]\n- [RFC 5987: Character Set and Language Encoding for Hypertext Transfer Protocol (HTTP) Header Field Parameters][rfc-5987]\n- [RFC 6266: Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP)][rfc-6266]\n- [RFC 8187: Indicating Character Encoding and Language for HTTP Header Field Parameters][rfc-8187]\n- [HTML Living Standard: Multipart form data][html-form]\n- [Test Cases for HTTP Content-Disposition header field (RFC 6266) and the Encodings defined in RFCs 2047, 2231 and 5987][tc-2231]\n\n[rfc-2616]: https://datatracker.ietf.org/doc/html/rfc2616\n[rfc-5987]: https://datatracker.ietf.org/doc/html/rfc5987\n[rfc-6266]: https://datatracker.ietf.org/doc/html/rfc6266\n[rfc-8187]: https://datatracker.ietf.org/doc/html/rfc8187\n[html-form]: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data\n[tc-2231]: http://greenbytes.de/tech/tc2231/\n\n## License\n\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/content-disposition\n[npm-url]: https://www.npmjs.com/package/content-disposition\n[node-version-image]: https://img.shields.io/node/v/content-disposition\n[node-version-url]: https://nodejs.org/en/download\n[coveralls-image]: https://img.shields.io/coverallsCoverage/github/jshttp/content-disposition\n[coveralls-url]: https://coveralls.io/github/jshttp/content-disposition?branch=master\n[downloads-image]: https://img.shields.io/npm/dm/content-disposition\n[downloads-url]: https://www.npmjs.com/package/content-disposition\n[github-actions-ci-image]: https://img.shields.io/github/actions/workflow/status/jshttp/content-disposition/ci.yml\n[github-actions-ci-url]: https://github.com/jshttp/content-disposition/actions/workflows/ci.yml\n","publish_time":1775596073748,"_cnpm_publish_time":1775596073748,"dist-tags":{"latest":"3.1.0","next":"1.0.0"}}