You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by "Brian J. Tarricone" <bj...@ece.cornell.edu> on 2003/07/14 22:32:56 UTC

[users@httpd] trouble with content negotiation

i'm trying to set up a site where i have duplicate images: .png and .jpg 
files.  i'd prefer the .png files, but of course i want to support older 
browsers that can't handle them.  i've gone over 
<http://httpd.apache.org/docs-2.0/content-negotiation.html> repeatedly, 
and done a search of the mailing list archives, but i'm still stuck.

i've tried both the type-map and MultiViews approaches, and neither 
seems to be working properly.  using type-maps (adding 'AddHandler 
type-map .var' to httpd.conf, and 'Options -MultiViews' in .htaccess), i 
just get 404 errors when trying to access the image without an 
extension.  i have .var files that look basically like the examples on 
the url mentioned above:

URI: image

URI: image.png
Content-type: image/png; qs=0.9

URI: image.jpg
Content-type: image/jpeg; qs=0.5

i've tried with and without the qs= settings, same result.  if i turn 
MultiViews on, it _appears_ to work, but the results are weird.  mozilla 
is sending the server an Accept: header with image/png before image/jpeg 
(with the same q= setting), but apache seems to be returning the jpeg 
for some of the images and a png for others (it's always the same ones).

is there something i'm missing?  i've read over the content negotiation 
docs repeatedly and i can't seem to find anything.  i'd prefer the 
MultiViews method as i don't feel like maintaining a set of .var files, 
however i'd be interested i knowing why the .var-file method isn't 
working for me.  i've tried putting the AddHandler statement in 
.htaccess as well to no avail.  i'm running apache 2.0.45 if that helps.

thanks,
brian


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] trouble with content negotiation

Posted by "Brian J. Tarricone" <bj...@ece.cornell.edu>.
Joshua Slive wrote:

>On Mon, 14 Jul 2003, Brian J. Tarricone wrote:
>  
>
>>>If the q= setting is the same, then apache is perfectly free to choose
>>>whatever image it wants.  I'd have to go through the code to be sure, but
>>>I suspect that it is sending the smaller ones.  Unfortunately, I don't
>>>think that there is any way on the server-side to specify a priority
>>>listing for content-type (like LanguagePriority does for language).
>>>      
>>>
>>hmm, that's a shame.  perhaps i'll try my hand at hacking on
>>mod_negotiation sometime...  personally i would think the 'correct'
>>behaviour would be to pick the first matching type in the Accept:
>>header, rather than picking the smallest file (if that is indeed the
>>case).  then again i'm sure there is a reason for it that i'm not aware
>>of...
>>    
>>
>
>I'd have to check the RFC to be sure,
>
i just skimmed thru rfc2295.  granted it is a long document and i don't 
have the time to pore over it right now, but it doesn't _appear_ to 
define server-side behaviour when the browser says it "doesn't care."  
don't take my word on that tho...

>but I don't believe there is any
>justification for giving significance to order when the quality values are
>the same.  The browser is explicitly saying that it doesn't care.
>  
>
how about consistency?  using my example, if i have a jpeg and png copy 
of every image, and the browser doesn't explicity say which it prefers 
through a q= value, what is to be gained over some arbitrary selection 
method (such as filesize)?  in my case it is giving undesired results - 
sometimes choosing the jpeg, other times the png.  using my quick script 
to create a jpeg from each png, i noticed the colours in the jpegs are 
slightly darker.  this looks terrible when the png images are mixed with 
the jpegs (they are site navigation link images).  i think this could be 
applied to other types/formats of data as well.  imho, the "best" 
behaviour would be for the server to attempt to be consistent and supply 
the same type each time.  since http is a stateless protocol, the only 
way to achieve this is to assume that the browser doesn't change the 
ordering of items in its Accept: header across requests, and satisfy the 
first type in the header for which it has a matching file.  this may 
seem like just another arbitrary selection method, but at least it has 
the benefit of type-consistency (unless the browser is mucking with its 
Accept: header for each request, but in that case i would say the 
browser is broken).

>I seem to recall that it may be possible to put server-side quality values
>using a type-map.  This may be the way to go.  See:
>http://www.apacheweek.com/features/negotiation
>  
>
yeah, that's what i've ended up doing, but it means i have to create an 
extra file for each image.  i wrote a script to generate the .var files, 
so it's not too big a deal, but i'd like to eliminate their necessity if 
possible.

    -brian


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] trouble with content negotiation

Posted by Joshua Slive <jo...@slive.ca>.
> i just skimmed thru rfc2295.  granted it is a long document and i don't
> have the time to pore over it right now, but it doesn't _appear_ to
> define server-side behaviour when the browser says it "doesn't care."
> don't take my word on that tho...

> > but I don't believe there is any justification for giving significance
> > to order when the quality values are the same.  The browser is
> > explicitly saying that it doesn't care.

> how about consistency?  using my example, if i have a jpeg and png copy
> of every image, and the browser doesn't explicity say which it prefers
> through a q= value, what is to be gained over some arbitrary selection
> method (such as filesize)?  in my case it is giving undesired results -
> sometimes choosing the jpeg, other times the png.

It could just as easily be argued that the server should consistently make
the same choice for any particular file across clients when the client
doesn't express a preference.  Your algorithm wouldn't do that.

In fact, it seems to me that using the ordering is far more arbitrary than
using the filesize, given that the ordering is explictly meaningless.

One more hint for you: I have heard that it may be possible to include a
quality value using the AddType directive in the same way that you do in
a type-map.  This could allow you to use multiviews rather than type-maps.
But again, I've never tried it myself.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] trouble with content negotiation

Posted by Joshua Slive <jo...@slive.ca>.
On Mon, 14 Jul 2003, Brian J. Tarricone wrote:
> >If the q= setting is the same, then apache is perfectly free to choose
> >whatever image it wants.  I'd have to go through the code to be sure, but
> >I suspect that it is sending the smaller ones.  Unfortunately, I don't
> >think that there is any way on the server-side to specify a priority
> >listing for content-type (like LanguagePriority does for language).
> >
> >
> hmm, that's a shame.  perhaps i'll try my hand at hacking on
> mod_negotiation sometime...  personally i would think the 'correct'
> behaviour would be to pick the first matching type in the Accept:
> header, rather than picking the smallest file (if that is indeed the
> case).  then again i'm sure there is a reason for it that i'm not aware
> of...

I'd have to check the RFC to be sure, but I don't believe there is any
justification for giving significance to order when the quality values are
the same.  The browser is explicitly saying that it doesn't care.

I seem to recall that it may be possible to put server-side quality values
using a type-map.  This may be the way to go.  See:
http://www.apacheweek.com/features/negotiation

I haven't tried this myself, but it looks like what you want.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] trouble with content negotiation

Posted by "Brian J. Tarricone" <bj...@ece.cornell.edu>.
Brian J. Tarricone wrote:

> Joshua Slive wrote:
>
>> This won't work.  If you want to use type-map negotiation, the client 
>> must
>> request the type-map file (.var) directly.
>
> ah, ok, i guess i just misunderstood.  that's probably what i'll end 
> up doing.

just to reply to myself...  i decided to take a slightly different 
tack.  just in case anyone is interested in what i did: i wanted to 
leave the references in the html as-is (i.e. extensionless, without a 
.var on them), so i put the following in .htaccess:

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_URI} !\..{1,4}$
RewriteRule (.*) $1\.var

it seems to work well enough, assuming you don't have files with dots in 
them that have 1<=x<=4 characters after them (i can't think of any image 
extensions more than 4 chars).

just thought i'd show off the coolness i just discovered in 
mod_rewrite.  thanks again for the help.

    -brian


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] trouble with content negotiation

Posted by "Brian J. Tarricone" <bj...@ece.cornell.edu>.
Joshua Slive wrote:

>This won't work.  If you want to use type-map negotiation, the client must
>request the type-map file (.var) directly.
>  
>
ah, ok, i guess i just misunderstood.  that's probably what i'll end up 
doing.  hopefully it'll still do what i want.  does apache still look at 
Accept: headers when doing type-map negotiation?  i guess i'm asking... 
if a browser doesn't include image/png in an Accept: header (but does 
include image/jpeg), will it still give the jpeg even if i list the jpeg 
with a lower quality setting in the type-map file?  since most browsers 
seem to stick */* at the end of Accept: lines...

>If the q= setting is the same, then apache is perfectly free to choose
>whatever image it wants.  I'd have to go through the code to be sure, but
>I suspect that it is sending the smaller ones.  Unfortunately, I don't
>think that there is any way on the server-side to specify a priority
>listing for content-type (like LanguagePriority does for language).
>  
>
hmm, that's a shame.  perhaps i'll try my hand at hacking on 
mod_negotiation sometime...  personally i would think the 'correct' 
behaviour would be to pick the first matching type in the Accept: 
header, rather than picking the smallest file (if that is indeed the 
case).  then again i'm sure there is a reason for it that i'm not aware 
of...

thanks so much for the quick and informative reply.

    -brian


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] trouble with content negotiation

Posted by Joshua Slive <jo...@slive.ca>.
On Mon, 14 Jul 2003, Brian J. Tarricone wrote:
> using type-maps (adding 'AddHandler
> type-map .var' to httpd.conf, and 'Options -MultiViews' in .htaccess), i
> just get 404 errors when trying to access the image without an
> extension.

This won't work.  If you want to use type-map negotiation, the client must
request the type-map file (.var) directly.

> if i turn
> MultiViews on, it _appears_ to work, but the results are weird.  mozilla
> is sending the server an Accept: header with image/png before image/jpeg
> (with the same q= setting), but apache seems to be returning the jpeg
> for some of the images and a png for others (it's always the same ones).

If the q= setting is the same, then apache is perfectly free to choose
whatever image it wants.  I'd have to go through the code to be sure, but
I suspect that it is sending the smaller ones.  Unfortunately, I don't
think that there is any way on the server-side to specify a priority
listing for content-type (like LanguagePriority does for language).

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org