Version 5 (modified by ietf@…, 10 years ago) (diff) |
---|
A proposal for optional error handling in processing the Content-Disposition header field
Extracting Parameter Values From Header Fields
To extract the value for a given parameter-name from an unparsed-string, parse the unparsed-string using the following grammar:
unparsed-string = *OCTET name *LWS "=" value [ ";" *OCTET ] value = <OCTET, except ";">
where the name production is a gramatical production that is a case-insensitive match for the given parameter-name. If the unparsed-string can be parsed by the grammar in multple ways, choose the one in which name appears as close to the beginning of the string as possible. If the unparsed-string cannot be parsed by the grammar above, return the empty string.
Decoding the File Name
To filename-decode an encoded-string, parse the encoded-string using the following grammar:
encoded-string = word *( 1*delimiter word ) delimiter = LWS word = <OCTET, except delimiter>
Consider each gramatical element (either a delimiter or a word) in the order they appear in the encoded-string:
- If the gramatical element is a delimiter, emit a SP character.
- If the gramatical element is a word, process the element as follows:
- If the word contains non-ASCII characters, emit the word (decoded as ISO-8859-1) and proceed to the next gramatical element.
- Let the url-unescaped-word be the word %-unescaped.
- Emit the url-unescaped-word (decoded as UTF-8) and proceed to the next grammatical element. (There's actually more sadness here if the url-unescaped-word isn't valid UTF-8.)
The emitted characters are the decoded file name.
Determining the File Name
To determine the file name indicated by a Content-Disposition header field, use the following algorithm:
- Let filename-star be the value extracted from the Content-Disposition header field for for the "filename*" parameter.
- If filename-star parses as a RFC5987-value, return the RFC5987-value of filename-star and abort these steps.
- Let filename be the value extracted from the Content-Disposition header field for the "filename" parameter.
- If filename is empty, instead let filename be the value extracted from the Content-Disposition header field for the "name" parameter.
- If filename is empty, return the empty string and abort these steps.
- Return the filename-decoding of filename.
Determining the Disposition
To determine the disposition-type, parse the Content-Disposition header field using the following grammar:
unparsed-string = *LWS nominal-type *OCTET nominal-type = "inline" / "filename" / "name" / ";"
If the Content-Disposition header field is non-empty and fails to parse, then the disposition type is "attachment". Otherwise, the disposition-type is "inline".
Processing the Content-Disposition Header Field
To process the Content-Disposition header field, use the following algorithm:
- Determine the disposition-type.
- If the disposition-type is "inline", then ...
- If the disposition-type is "attachment", then let filename be the file name indicated by the header field. ...