简体   繁体   中英

Which separator should be used in the Content-Type header for a multipart data request? Comma or Semicolon?

Should the Content-Type header in a REST API web request be formatted with a comma as in RFC 1867 :

Content-type: multipart/form-data, boundary=AaB03x

Or with a semicolon, as in RFC 1049 and RFC 2045 :

Content-Type: multipart/mixed; boundary=gc0p4Jq0M2Yt08j34c0p

It's really all just a simple mistake and the ; is correct.

RFC 1867 was an experimental definition. All subsequent definitions have corrected this mistake. For example:

  • RFC 2388 explicitly replaces 1867 and refers to HTML 40 for the (correct) definition of the separator.
  • RFC 7231 explicitly refers to 2388 as the definition to use in HTTP/1.1.

And finally... there is also an official correction to RFC 1867 to make it use the correct delimiter.

Rely on the newest RFC: 7231, section 3.1.1.1 says:

media-type = type "/" subtype *( OWS ";" OWS parameter )

This leaves no room for interpretations or custom formats.

Unfortunately, it's not the first case I see, when several RFCs conflicts one with another.

In this exact case, RFC 1049 is explicitly cover Content-type header. RFC 2045 is referencing to RFC 1049. Moreover, RFC 2045 dated November 1996, so it's latest one.

Opposite case is covered in RFC 1867 very briefly.

So, I suggest to use semi-colon.

Note that your two conflicting examples aren't really contradictory. The first, RFC-1867, defines extensions to HTML. The other two, RFC-1049 and RFC-2045, both define extensions to the Internet Mail protocol.

For a REST API, I would probably go with RFC-1867, which was designed with HTML over HTTP in mind, as opposed to the other two, which were designed with RFC-822-based emails over SMTP/POP/IMAP in mind.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM