workspacereference / tools / guidesPUBLIC TOOLS
Buildwell Utilities
Browse ▾
GUIDES / HTTP REFERENCE

Choose the right Content-Type.

The Content-Type response header tells a client how to interpret bytes. It is part of the response contract.

Editorial team ·

Match the representation

An HTML document is ordinarily sent as text/html, a stylesheet as text/css and a JavaScript file with an appropriate JavaScript media type. JSON uses application/json. The filename extension alone is not a reliable substitute for response metadata, especially when an application routes different resources through one endpoint. Inspect the actual response headers, then verify that the delivered body has the expected syntax. A browser may tolerate mistakes that another client refuses.

Account for character encoding

Text content can declare a charset parameter, commonly UTF-8, when applicable. The encoding in the header should agree with the bytes emitted by the server. Mislabelled encoding can turn quotation marks or non-English text into replacement characters. For JSON exchanged across modern systems, UTF-8 is the interoperable choice. If you serve a text file without declaring a type, do not assume every browser will infer the same representation.

Do not rely on sniffing

Some clients try to infer file formats when metadata is missing or inconsistent. That behaviour can turn an incorrectly served upload into an executable document. X-Content-Type-Options: nosniff reduces particular content-sniffing behaviours in browsers, but it is useful only alongside correct media types. Validate upload types and separate untrusted content from application pages rather than expecting a header to repair an unsafe file-handling design.

Check with two requests

Retrieve the headers with a HEAD request and inspect a representative GET response as well. A properly implemented HEAD omits the body; it should describe the corresponding GET representation. Confirm that redirects, missing resources and error pages each return a suitable status and body type. A friendly 404 document is still a 404 response. Keep a small table of important routes and expected media types so configuration changes have an observable acceptance test.

Related reading

Continue with the guides index, or explore the overview for the wider context. Use a test resource on a server you control and inspect the complete response, including status and headers. Change one condition at a time, so the result remains interpretable. The guide explains protocol behaviour; it does not assert measurements from an external service.