What is the difference between ContentType and MimeType

As far as I know, they are absolutely equal. However, while looking through some django docs, I found this piece of code:

HttpResponse.__init__(content='', mimetype=None, status=200, content_type='text/html')

which surprise me in that they get along with each other. Official documents were able to solve the problem in their own way:

content_type is an alias for mimetype. Historically, this parameter was called mimetype, but since it is actually a value included in the HTTP Content-Type, it can also include character set encoding, which makes it more than just a MIME type specification. If the mimetic is (not None), this value is equally used. Otherwise, content_type is used. If none of them are specified, the DEFAULT_CONTENT_TYPE parameter is used.

However, I do not find this clarifying enough. Why do we use 2 different names for (almost the same) thing? Is "Content-Type" just a name used in browser requests and with very little use outside of it?

What is the main difference between each, and when is it right to call something a mimetype , not a content-type ? Am I a pitty and a Nazi grammar?

+74
content-type python mime-types django
Aug 10 2018-10-10T00:
source share
4 answers

Why do we use 2 different names for a (almost the same) thing? Is "Content-Type" just the name used in browser requests, and with very little use it outside?

What is the main difference between each, and when is the right to call something like mimetype, as opposed to a content type? Am I a pitti and grammar of the nazi?

The reason is not only backward compatibility, and I'm afraid that the usually excellent Django documentation is a little manual. MIME (it’s really worth reading at least a Wikipedia entry) has its beginning in the distribution of Internet mail and, in particular, SMTP. From there, the design of the MIME and MIME extension inspired many other protocols (such as HTTP here) and is still used when new types of metadata or data need to be transferred in the existing protocol. There are dozens of RFCs that discuss MIME used for a variety of purposes.

In particular, Content-Type: is one of several MIME headers. "Mimetype" does sound obsolete, but the link to MIME itself is not the same. Call this backward compatibility part if you want.

[By the way, this is a purely terminological problem that has nothing to do with grammar. Submitting each usage question under β€œgrammar” is my homepage. Grrrr.]

+41
Aug 10 '10 at 19:50
source share

I have always considered contentType as a superset of mimeType. The only difference is the encoding with an arbitrary set of characters. If the contentType does not contain an optional character set encoding, then it is identical to mimeType. Otherwise, mimeType is the data before the character set encoding sequence.

eg. text/html; charset=UTF-8

text/html - mimeType
; - indicator of additional parameters
charset=UTF-8 is a character set encoding parameter

eg. application/msword

application/msword - mimeType
It cannot have a character set encoding, since it describes a well-formed octet-stream that does not contain characters directly.

+25
Jul 30 '13 at 14:06 on
source share

If you want to know more, see ticket 3526 .

Quote:

Added content_type as an alias for mimetype for the HttpResponse constructor. This is a little more exact name. Based on a patch from Simon Willison. Fully backward compatible.

+4
Aug 10 '10 at 21:41
source share

Why do we use 2 different names for (almost the same) thing?

Backward compatibility based on your quote from the documentation.

0
Aug 10 2018-10-18
source share