wiki:ContentDispositionErrorHandling

Version 8 (modified by ietf@…, 9 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  = block * ( ";" block ) [ ";" unbalanced-block ]
block            = *run
unbalanced-block = *run unbalanced-run
run              = unquoted-run / quoted-run
unquoted-run     = non-quote *boring-octet
quoted-run       = <"> *non-quote <">
unbalanced-run   = <"> *non-quote
non-quote        = <OCTET, except <"> >
boring-octet     = <OCTET, except <"> and ";">

Parse each block, in turn, using the following grammar:

block = *LWS name *LWS "=" value
value = OCTET

where the name production is a gramatical production that is a case-insensitive match for the given parameter-name. If any block can be parsed by the grammar, return the characters produced by the value production of the first such block. If none of the blocks can be parsed using this grammer, return the empty string.

Decoding the File Name

To filename-decode an encoded-string, use the following algorithm:

  1. If the encoded-string contains non-ASCII characters, emit the encoded-string (decoded as ISO-8859-1) and abort these steps.
  2. Let the url-unescaped-string be the encoded-string %-unescaped.
  3. Emit the url-unescaped-string (decoded as UTF-8). (There's actually more sadness here if the url-unescaped-string 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:

  1. Let filename-star be the value extracted from the Content-Disposition header field for for the "filename*" parameter.
  2. If filename-star parses as a RFC5987-value, return the RFC5987-value of filename-star and abort these steps.
  3. Let filename be the value extracted from the Content-Disposition header field for the "filename" parameter.
  4. If filename is empty, instead let filename be the value extracted from the Content-Disposition header field for the "name" parameter.
  5. If filename is empty, return the empty string and abort these steps.
  6. 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:

  1. Determine the disposition-type.
  2. If the disposition-type is "inline", then ...
  3. If the disposition-type is "attachment", then let filename be the file name indicated by the header field. ...