What is MIME type "text/x-chdr"?

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

The MIME type text/x-chdr identifies files meant for C header code. These files hold function declarations, macros, and type definitions. They generally use the H extension.
This type tells tools and browsers that the file contains structured code rather than simple text.

The MIME type streamlines file handling in development environments. For more details, consider visiting resources like IANA media types.

Associated file extensions

Usage Examples

HTTP Header

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


    Content-Type: text/x-chdr    
  

HTML

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


    <a href="file.dat" type="text/x-chdr">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-chdr');    
      res.end('Content here');    
    }).listen(3000);    
  

Associated file extensions

FAQs

What is the text/x-chdr MIME type used for?

The MIME type text/x-chdr is used to identify C header files, which typically carry the .h extension. It indicates to web servers, browsers, and text editors that the content is structured C programming code containing declarations and macros, rather than generic plain text.

How do I configure Apache to serve .h files as text/x-chdr?

You can configure Apache by adding a directive to your .htaccess file or main configuration. Use the line AddType text/x-chdr .h to ensure files with the h extension are served with the correct Content-Type header.

How do I add text/x-chdr support to Nginx?

In Nginx, you should update the mime.types file usually found in /etc/nginx/. Add the line text/x-chdr h; inside the types { ... } block, or add it manually to your nginx.conf to ensure proper handling of header files.

Will web browsers execute files served as text/x-chdr?

No, browsers will not execute C header files. Because the MIME type starts with text/, most modern browsers (like Chrome and Firefox) will simply display the code as plain text in the browser window, allowing users to read the source code.

What does the 'x-' prefix mean in text/x-chdr?

The x- prefix indicates that this is a non-standard or experimental MIME type not officially registered with the IANA core registry. However, it is widely accepted by operating systems and web servers as the de facto standard for C header files.

Is it safe to serve text/x-chdr files publicly?

It depends on your intent. Serving text/x-chdr exposes your source code definitions and internal logic to the public. If the code is proprietary or contains sensitive macro definitions, you should restrict access via server permissions; if it is open-source documentation, serving it is safe.

Can I use text/plain instead of text/x-chdr?

Yes, you can use text/plain, and browsers will still display the content correctly. However, using text/x-chdr is semantically more accurate and helps specialized tools or browser extensions apply the correct syntax highlighting for C code.

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.