質問

We have some code that processes messages based on mimetypes, which requires matching them. A cursory glance suggests are all lower-case, which leads one to wonder if:

  • they are so by convention, or
  • is that part of the spec? (a search of RFC 2045/2046 for upper/lower case etc. did not return any hits)

So, can the case insensitive compare be omitted for the tiny performance boost ?

役に立ちましたか?

解決

MIME types are case insensitive. They are lowercase by convention only.

RFC 2045 says: "The type, subtype, and parameter names are not case sensitive." If you have a MIME type of text/plain that's a type of text and a subtype of plain. So, per the spec, these are not case sensitive.

As Cromax notes in a comment, MIME type parameter values may be case-sensitive. See the comment or the spec for details. But if you're matching only the mime type, subtype, or parameter names, they are case insensitive. Anecdotally, most people work with mime type and maybe subtype, and those are case insensitive.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top