content-disposition-parse
v0.0.3
Published
Parse Content-Disposition header
Downloads
28
Maintainers
Readme
content-disposition-parse
Parse HTTP Content-Disposition
header based on this content-disposition
Installation
$ npm install content-disposition-parse
Example
const { ContentDisposition } = require('content-disposition-parse');
const result = ContentDisposition.parse('attachment; filename="example.txt"');
console.log(result);
//output result
{ type: 'attachment', parameters: { filename: 'example.txt' } }
Usage
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.
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"}
References
- RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1
- RFC 5987: Character Set and Language Encoding for Hypertext Transfer Protocol (HTTP) Header Field Parameters
- RFC 6266: Use of the Content-Disposition Header Field in the Hypertext Transfer Protocol (HTTP)
- Test Cases for HTTP Content-Disposition header field (RFC 6266) and the Encodings defined in RFCs 2047, 2231 and 5987