Content negotiation
From Wikipedia, the free encyclopedia
HTTP |
Persistence · Compression · SSL |
Headers |
ETag · Cookie · Referer |
Status codes |
200 OK |
301 Moved permanently |
302 Found |
403 Forbidden |
404 Not Found |
Content negotiation is a mechanism defined in the HTTP specification that makes it possible to serve different versions of a document (or more generally, a resource) at the same URI, so that user agents can choose which version fit their capabilities the best. One of the most classical uses of this mechanism is to serve an image as both GIF and PNG, so that a browser that doesn't understand PNG can still display the GIF version. To summarize how this works, it's enough to say that user agents are supposed to send an HTTP header (Accept
) with the various media types they understand and with indications of how well they understand it. Then, the server replies with the version of the resource that fits the user agents' needs.
So, a resource may be available in several different representations. For example, it might be available in different languages or different media types, or a combination. One way of selecting the most appropriate choice is to give the user an index page, and let them select. However it is often possible for the server to choose automatically. This works because browsers can send as part of each request information about the representations they prefer. For example, a browser could indicate that it would like to see information in French, if possible, else English will do. Browsers indicate their preferences by headers in the request. To request only French representations, the browser would send
Accept-Language: fr
Note that this preference will only be applied when there is a choice of representations and they vary by language.
As an example of a more complex request, this browser has been configured to accept French and English, but prefer French, and to accept various media types, preferring HTML over plain text or other text types, and preferring GIF or JPEG over other media types, but also allowing any other media type as a last resort:
Accept-Language: fr; q=1.0, en; q=0.5 Accept: text/html; q=1.0, text/*; q=0.8, image/gif; q=0.6, image/jpeg; q=0.6, image/*; q=0.5, */*; q=0.1
This article may require cleanup to meet Wikipedia's quality standards. Please improve this article if you can. (January 2008) |
More information needed on how to do Content Negotiation in IIS IIS 5.1 Clean URLs Extensionless URLs Language Negotiation Mime Type Negotiation qs values: Quality of content source. IE: Images such as .png/.jpg/.gif IIS 6.0 Clean URLs Extensionless URLs Language Negotiation Mime Type Negotiation qs values: Quality of content source. IE: Images such as .png/.jpg/.gif IIS 7.0 Clean URLs Extensionless URLs Language Negotiation Mime Type Negotiation qs values: Quality of content source. IE: Images such as .png/.jpg/.gif Wildcard Mapping ISAPI filters ISAPI extensions 404 Mapping Alternatives when your web host doesn't allow ISAPI filter installation
[edit] See also
[edit] External links
- RFC 2616 – Hypertext Transfer Protocol -- HTTP/1.1 – (Section 12: Content Negotiation)
- RFC 2295 – Transparent Content Negotiation in HTTP
- Apache Content Negotiation
- Open source PHP content negotiation library (supports wildcards and q values)
- Content negotiation techniques to serve XHTML as
text/html
andapplication/xhtml+xml
- XHTML content negotiation using object-oriented PHP
- The variant button