Hi all,

We do have a mechanism to customize the conneg based on the client browser 
name. Check the TunnelService Javadocs for details. There
is a default "org/restlet/service/accept.properties" file in the Restlet JAR 
that you can override if needed.

Let me know if something is unclear!

Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com
 

-----Message d'origine-----
De : Simon Reinhardt [mailto:[email protected]] 
Envoye : vendredi 30 janvier 2009 21:25
A : [email protected]
Objet : Custom conneg for (X)HTML media types

Hi,

When working with XHTML you have to be careful how to deliver it. The 
appropriate content type is application/xhtml+xml in which
case the supporting browser will treat it as XML (for parsing, in the DOM and 
in CSS for example). However non-supporting browsers
like IE will choke on that and offer you the page for download. Therefore you 
can alternatively serve it as text/html - with the
disadvantage that it will be parsed and treated as HTML.
Now, of course you can look into the Accept header to find out if the browser 
will support XHTML or not and serve it under an
appropriate content type accordingly. The problem with that are the Accept 
headers that browsers actually send. Opera and FF ask for
both media types, with the same preference, text/html coming first. IE doesn't 
ask for any HTML media type at all but just tells you
that it accepts some other stuff and then anything with a preference of 1. So, 
the default conneg algorithm doesn't work here: If I
register two variants, the HTML one coming first, then all browsers will get 
the HTML version. If I register two variants, the XHTML
one coming first, then all browsers will get the XHTML version, even IE which 
doesn't support it.
This situation was being recognised by the W3C and they came up with a custom 
conneg algorithm [1]. The idea is to only serve XHTML
when it is explicitly listed in the Accept header - and when it is, give it 
precedence over HTML. They say there that you should do
that for XHTML documents that follow the compatibility guidelines and therefore 
can be rendered by non-supporting browsers properly,
so they don't really do conneg but just serve one variant with different media 
types. But of course nothing stops you from really
writing two variants, one in HTML 4.01 and one in XHTML+SVG+MathML for example 
(the latter wouldn't be valid to serve as text/html
at all).

So the question here is, can you think of an easy way to implement this custom 
conneg (or rather just Accept-header inspection)
algorithm in Restlet?

Thanks,
  Simon

[1] http://www.w3.org/TR/2009/NOTE-xhtml-media-types-20090116/#media-types

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1076412

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1079748

Reply via email to