You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Roy T. Fielding" <fi...@avron.ICS.UCI.EDU> on 1995/03/16 16:13:30 UTC
Re: Content-type negotiation: thoughts and code
rst was saying:
> This code does a *basic* job of content-type negotiation --- it parses
> everything (at least according to my reading of the relevant standards
> documents, and the CERN code), but it doesn't actually use the
> Accept-content-encoding and Accept-language info yet; however, it does
I'd recommend not looking at the CERN code and just use the latest
HTTP/1.0 as a reference. If you find parts that don't make sense in the
spec, please take notes and forward them to me -- you will probably
be the first to implement it right.
There is no "Accept-content-encoding" -- only Accept-Encoding.
> handle qualities. (It also doesn't yet return the correct HTTP error
> codes in all cases --- in particular, it returns 404 Not Found, rather
> than 406 None Acceptable, when content-type negotiation does find
> alternate views, of which none are acceptable).
Well, that's not useful -- that would be a bug. Lack of 406 is the
main reason content negotiation has failed in the past.
>[...]
> A second interesting thing which comes up is what to do with clients
> like certain, ahem, colorful browser betas which ship completely bogus
> Accept: headers (or HTTP/0.9 browsers, which don't ship any). My code
> basically pretends the browser did "Accept: text/html" and "Accept:
> text/plain" whether it actually did or not, to ease this difficulty;
> is that the right thing?
Nope, though that is what the old spec said. The "official" default
is "*/*" -- HTTP/0.9 clients cannot (and, in general, do not) assume
that what they are getting is HTML.
>[...]
> As a final point, writing the code raises the question of what the
> map files should look like. What I've done probably isn't the right
> thing, but a discussion of what's wrong with it might prove
> instructive. The map files implemented by my code just look like:
>
> foo.au: audio/basic
> foo.gif: image/gif
> foo.html: text/html
> foo.txt: text/plain
That syntax is inherently limiting -- one dimension (media type) only.
Since we know that more dimensions are on the way, the syntax should prepare
for them. The suggestions below are better.
> (this being the contents of foo.map). Qualities can be associated
> with these ---
>
> foo.gif: image/gif; q = 0.6
> foo.jpeg: image/jpeg; q = 1.0
> foo.xbm: image/x-xbitmap; q = 0.00001
That should be "qs" instead of "q", to match the description in the spec.
>[...]
> My question for the group is, what else do we want? Extra MIME header
> lines? Some way of discriminating on USER_AGENT? (FWIW, I was
> thinking vaguely of a syntax along the lines of:
>
> foo.aiff {
> Content-type: audio/aiff; q=1.0
> Pass-along-this-mime-hdr: Kilroy was here
> }
>
> foo.au {
> Content-type: audio/basic; q=0.2
> Pass-along-this-mime-hdr: Klrooy wuzzz heerere
> }
>
> I have a truly marvelous implementation of this in mind, but my
> weekend was too small to contain it ;-).
Yeah, that's my problem as well. What you have just reinvented is a
proposed syntax for URCs (for more info on that, see
<http://union.ncsa.uiuc.edu/HyperNews/get/www/URCs.html>).
If you want to see what I consider to be the ideal syntax for a new
media type for carrying URCs ("meta/prdm"), see
<http://www-diglib.stanford.edu/rmr/TR/TR.html#APPENDIXB>.
A simpler syntax is what I call "meta/http", which is just a series of
HTTP headers separated by blank lines:
URI: foo; vary="type,language"
URI: foo.jpeg
Content-length: 3456
Content-type: image/jpeg; qs=1.0
Content-language: en
URI: foo.gif
Content-type: image/gif; qs=0.7
Content-length: 123456
Content-language: en
URI: foo.gif
Content-type: image/gif; qs=0.7
Content-length: 126543
Content-language: fr
URI: http://www.inria.fr/Images/foo.gif
Content-type: image/gif; qs=0.7
Content-length: 126543
Content-language: fr
The key is this: If the client's accept headers were not sufficient
to determine the "best" choice, then the server would send a
"300 Multiple Choices" response and include this "meta/http" as the
message body -- an enhanced client can then do a redirect on this response.
Note that the last one is a mirror entry and would be ignored by
the server's internal content negotiation.
More importantly, we can eventually move from pre-emptive negotiation and
just have the server return a "meta/*" content whenever multiple choices
do exist (a rare event). This is likely to occur soon after some form
of short-term keep-alive is implemented for HTTP/1.1.
The meta/http format is okay for access redirection, but the PRDM format
will be much better for eventual handling of URI->URC->URL redirection
and resource discovery systems.
Mind you, all of these are just ideas -- one of these days I'll get
around to writing a paper.... I would not expect any of this to show
up in an early version of Apache.
......Roy Fielding ICS Grad Student, University of California, Irvine USA
<fi...@ics.uci.edu>
<URL:http://www.ics.uci.edu/dir/grad/Software/fielding>