关于http标头:PDF文件的正确MIME媒体类型

Proper MIME media type for PDF files

在使用pdf时,我遇到了mime类型application/pdfapplication/x-pdf等。

这两种类型之间有区别吗?如果有,是什么?一个比另一个更受欢迎吗?

我正在开发一个网络应用程序,它必须提供大量的PDF文件,如果有,我想用正确的方式来实现。


标准的mime类型是application/pdf。该分配在RFC3778(应用程序/pdf媒体类型)中定义,引用自mime媒体类型注册表。

mime类型由标准机构(InternetAssignedNumberAuthority,IANA)控制。这是管理根名称服务器和IP地址空间的同一个组织。

x-pdf的使用早于PDF的mime类型的标准化。x-名称空间中的mime类型被认为是实验性的,正如vnd.名称空间中的mime类型被认为是特定于供应商的。x-pdf可用于与旧软件兼容。


这是在RFC2045-多用途因特网邮件扩展(MIME)第1部分:因特网消息正文格式中定义的一种约定。

  • Private [subtype] values (starting with"X-") may be defined
    bilaterally between two cooperating agents without
    outside registration or standardization. Such values
    cannot be registered or standardized.

  • New standard values should be registered with IANA as described in RFC 2048.

  • 类似的限制也适用于顶级类型。从同一个来源,

    If another top-level type is to be used for any reason, it must be
    given a name starting with"X-" to indicate its non-standard status
    and to avoid a potential conflict with a future official name.

    (请注意,根据RFC 2045,"媒体类型和子类型的[M]匹配始终不区分大小写",因此"x-"和"x-"的解释没有区别。)

    因此,可以公平地猜测,在IANA定义"application/foo"之前使用了"application/x-foo"。它仍然可能被那些不知道IANA令牌分配的人使用。

    正如克里斯·汉森所说,哑剧类型是由IANA控制的。这在RFC2048-多用途因特网邮件扩展(mime)第四部分:注册程序中有详细说明。根据IANA引用的RFC3778作为"应用程序/pdf"的定义,

    The application/pdf media type was first registered in 1993 by Paul Lindner for use by the gopher protocol; the registration was subsequently updated in 1994 by Steve Zilles.

    "application/pdf"类型已经存在了十多年。所以在我看来,无论"application/x-pdf"在新的应用程序中被使用到哪里,这个决定可能都不是经过深思熟虑的。


    从维基百科媒体类型,

    A media type is composed of a type, a subtype, and optional
    parameters. As an example, an HTML file might be designated text/html; charset=UTF-8.

    Media type consists of top-level type name and sub-type name, which is
    further structured into so-called"trees".

    1
    2
    3
    top-level type name / subtype name [ ; parameters ]

    top-level type name / [ tree. ] subtype name [ +suffix ] [ ; parameters ]

    所有媒体类型都应使用IANA注册程序进行注册。目前创建的树有:standardvendorpersonalvanity、未注册的x.

    标准:

    Media types in the standards tree do not use any tree facet (prefix).

    1
    type / media type name [+suffix]

    示例:"application/xhtml+xml","image/png"

    小贩:

    Vendor tree is used for media types associated with publicly available
    products. It uses vnd. facet.

    1
    2
    3
    4
    5
    type / vnd. media type name [+suffix] - used in the case of well-known producer

    type / vnd. producer's name followed by media type name [+suffix] - producer's name must be approved by IANA

    type / vnd. producer's name followed by product's name [+suffix] - producer's name must be approved by IANA

    个人或化妆树:

    Personal or Vanity tree includes media types created experimentally or
    as part of products that are not distributed commercially. It uses
    prs. facet.

    1
    type / prs. media type name [+suffix]

    未注册的x.树:

    The"x." tree may be used for media types intended exclusively for use
    in private, local environments and only with the active agreement of
    the parties exchanging them. Types in this tree cannot be registered.

    According to the previous version of RFC 6838 - obsoleted RFC 2048
    (published in November 1996) it should rarely, if ever, be necessary
    to use unregistered experimental types, and as such use of both"x-"
    and"x." forms is discouraged. Previous versions of that RFC - RFC
    1590 and RFC 1521 stated that the use of"x-" notation for the
    sub-type name may be used for unregistered and private sub-types, but
    this recommendation was obsoleted in November 1996.

    1
    type / x. media type name [+suffix]

    因此很明显,标准类型的mime-type application/pdf是合适的,而您应该避免使用如RFC 2048和RFC 6838所述的过时和未注册的x-媒体类型。