Blog

DIY tips: HTTP content negotiation

2007-06-05 18:16:08 by Martynas Jusevičius

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 URL, so that user agents can choose which version fit their capabilities the best [Wikipedia].

Negotiation is based on HTTP Accept headers that the clients send. It can be used for different things, such as determining client's language or locale, but we mainly use it to deliver our content with the right MIME content type. That is important when delivering XHTML since the correct content type for it is application/xhtml+xml while plain old HTML should be served with text/html.

These are the only 2 lines that do the negotiation in our XSLTView class. They serve the XHTML content type to clients that support it (Internet Explorer does not) or revert to HTML otherwise:

if (strstr($request->getHeader("HTTP_ACCEPT"), ContentType::XHTML_XML)) $response->setContentType(ContentType::XHTML_XML);
else $response->setContentType(ContentType::TEXT_HTML);

Digg Digg this! del.icio.us del.icio.us!

Comments (2)

TIFFANY

2010-07-26 11:45:13 by tiffany jewelry

he brick façades, the green rolling hills, the bell tower…and the totally awesome colors of Blue&Gold draping the campus. And—as Jane and Kevin can attest—Bruins have good taste!

Cisco Specialist

2010-09-08 12:23:36 by Cisco Specialist

Content negotiation is a mechanism defined in the HTTP specification that makes it feasible to serve different versions of a document (or more usually, a resource) at the same URL, so that user agents can pick which version fit their capabilities the best

New comment






No HTML allowed.