What is MIME type "text/x-c++hdr"?

A MIME type is a string that tells browsers and other tools how to handle a particular kind of file.

MIME type: text/x-c++hdr tells the system the file holds C++ header code. It marks files that contain declarations, prototypes, and interface details for C++ programs.

This type is key in many code editors and development tools. They use it to apply correct syntax highlighting and formatting. The text-based format makes the code easy to read and edit.

Use cases include:

Files using this MIME type often have extensions like H, HPP, HP, HH, HXX, and H++.

Associated file extensions

Usage Examples

HTTP Header

When serving content with this MIME type, set the Content-Type header:


    Content-Type: text/x-c++hdr    
  

HTML

In HTML, you can specify the MIME type in various elements:


    <a href="file.dat" type="text/x-c++hdr">Download file</a>    
  

Server-side (Node.js)

Setting the Content-Type header in Node.js:


    const http = require('http');    
    
    http.createServer((req, res) => {    
      res.setHeader('Content-Type', 'text/x-c++hdr');    
      res.end('Content here');    
    }).listen(3000);    
  

Associated file extensions

FAQs

How do I configure Apache to serve C++ header files correctly?

To ensure Apache serves C++ headers with the correct MIME type, add the following line to your .htaccess file or main configuration: AddType text/x-c++hdr .hpp .hh .hxx .h++. This ensures browsers and development tools recognize the content specifically as C++ code rather than generic text.

Why do browsers display text/x-c++hdr files as plain text?

Since the MIME type starts with text/, browsers interpret the content as human-readable data. This allows developers to view source code in files like .hpp or .h directly in the browser window without being forced to download the file first.

What is the difference between text/x-c++hdr and text/plain?

While both types indicate text content, text/x-c++hdr explicitly identifies the file as a C++ header. Using the specific type helps IDEs, code repositories, and indexers apply appropriate C++ syntax highlighting and formatting, whereas text/plain offers no context about the programming language.

How do I add the text/x-c++hdr MIME type in IIS?

In Internet Information Services (IIS), select your site, double-click MIME Types, and select Add from the actions pane. Enter the file extension (such as .hpp) and set the MIME type to text/x-c++hdr. Without this mapping, IIS may return a 404 error for these static files.

What does the 'x-' prefix mean in text/x-c++hdr?

The x- prefix indicates that text/x-c++hdr is a non-standard or experimental type, as opposed to an IANA-standardized media type. Despite this, it is the widely accepted convention for identifying C++ header files on web servers and Linux systems.

Should .h files be mapped to text/x-c++hdr or text/x-chdr?

It depends on the primary language of your project. The .h extension is used by both C and C++. If your project is C++, mapping .h to text/x-c++hdr is preferred; if it is pure C, text/x-chdr is more accurate. For mixed environments, text/plain is often used as a neutral fallback.

General FAQ

What is a MIME type?

A MIME (Multipurpose Internet Mail Extensions) type is a standard that indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.

MIME types are important because they help browsers and servers understand how to process a file. When a browser receives a file from a server, it uses the MIME type to determine how to display or handle the content, whether it's an image to display, a PDF to open in a viewer, or a video to play.

MIME types consist of a type and a subtype, separated by a slash (e.g., text/html, image/jpeg, application/pdf). Some MIME types also include optional parameters.

How do I find the MIME type for a file?

You can check the file extension or use a file identification tool such as file --mime-type on the command line. Many programming languages also provide libraries to detect MIME types.

Why are multiple MIME types listed for one extension?

Different applications and historical conventions may use alternative MIME identifiers for the same kind of file. Showing them all helps ensure compatibility across systems.