Gathering detailed insights and metrics for @otterhttp/content-disposition
Gathering detailed insights and metrics for @otterhttp/content-disposition
ESM Express-like web framework for modern Node.js
npm install @otterhttp/content-disposition
Typescript
Module System
Min. Node Version
Node Version
NPM Version
68.7
Supply Chain
97.4
Quality
76.7
Maintenance
100
Vulnerability
79.9
License
TypeScript (99.98%)
Shell (0.02%)
Total Downloads
625
Last Day
1
Last Week
6
Last Month
29
Last Year
625
2,103 Commits
2 Branches
57 Contributors
Latest Version
3.1.0
Package Id
@otterhttp/content-disposition@3.1.0
Unpacked Size
8.42 kB
Size
3.45 kB
File Count
5
NPM Version
10.8.1
Node Version
20.16.0
Publised On
16 Aug 2024
Cumulative downloads
Total Downloads
Last day
-87.5%
1
Compared to previous day
Last week
-40%
6
Compared to previous week
Last month
-39.6%
29
Compared to previous month
Last year
0%
625
Compared to previous year
1
content-disposition
rewrite in TypeScript.
Create and parse HTTP Content-Disposition
header
1pnpm i @otterhttp/content-disposition
1import { contentDisposition, parse } from '@otterhttp/content-disposition'
contentDisposition(filename)
Create an attachment Content-Disposition
header value using the given file
name, if supplied. The filename
is optional and if no file name is desired,
but you want to specify options
, set filename
to undefined
.
1res.setHeader('Content-Disposition', contentDisposition('∫ maths.pdf'))
note HTTP headers are of the ISO-8859-1 character set. If you are writing
this header through a means different from setHeader
in Node.js, you'll want
to specify the 'binary'
encoding in Node.js.
contentDisposition
accepts these properties in the options object.
fallback
If the filename
option is outside ISO-8859-1, then the file name is actually
stored in a supplemental field for clients that support Unicode file names and a
ISO-8859-1 version of the file name is automatically generated.
This specifies the ISO-8859-1 file name to override the automatic generation or
disables the generation all together, defaults to true
.
false
will disable including a ISO-8859-1 file name and only include the
Unicode version (unless the file name is already ISO-8859-1).true
will enable automatic generation if the file name is outside
ISO-8859-1.If the filename
option is ISO-8859-1 and this option is specified and has a
different value, then the filename
option is encoded in the extended field and
this set as the fallback field, even though they are both ISO-8859-1.
type
Specifies the disposition type, defaults to "attachment"
. This can also be
"inline"
, or any other value (all values except inline are treated like
attachment
, but can convey additional information if both parties agree to
it). The type is normalized to lower-case.
contentDisposition.parse(string)
1contentDisposition.parse('attachment; filename="EURO rates.txt"; filename*=UTF-8\'\'%e2%82%ac%20rates.txt')
Parse a Content-Disposition
header string. This automatically handles extended
("Unicode") parameters by decoding them and providing them under the standard
parameter name. This will return an object with the following properties
(examples are shown for the string
'attachment; filename="EURO rates.txt"; filename*=UTF-8\'\'%e2%82%ac%20rates.txt'
):
type
: The disposition type (always lower case). Example: 'attachment'
parameters
: An object of the parameters in the disposition (name of
parameter always lower case and extended versions replace non-extended
versions). Example: {filename: "€ rates.txt"}
This simple example shows how to use accepts
to return a different typed
respond body based on what the client wants to accept. The server lists it's
preferences in order and will get back the best match between the client and
server.
1import { contentDisposition } from '@otterhttp/content-disposition' 2import destroy from 'destroy' 3import fs from 'node:fs' 4import { createServer } from 'node:http' 5import onFinished from 'on-finished' 6 7const filePath = '/path/to/public/plans.pdf' 8 9createServer((req, res) => { 10 res.setHeader('Content-Type', 'application/pdf') 11 res.setHeader('Content-Disposition', contentDisposition(filePath)) 12 13 const stream = fs.createReadStream(filePath) 14 stream.pipe(res) 15 onFinished(res, () => destroy(stream)) 16})
No vulnerabilities found.
No security vulnerabilities found.