Jrgns
Jrgns

Reputation: 25197

Interpreting Accept Headers as intended in IE and Webkit

I developed a web app that responds with data in the format as specified by the client in the HTTP Accept Headers. Everything worked fine while using Firefox, but when I wanted to check my CSS / HTML on Chrome and IE, both of them wanted to download the index page, as if it's an unknown content type.

After some research I found this article, which states that IE sends out a lot of crud in it's HTTP Accept headers, amongst others a list of image/* content types right at the start.

This caused my web app to try to send the index page as an image/jpeg.

So how do I know when to ignore and when to use the Accept Headers?

Upvotes: 3

Views: 488

Answers (2)

Jan Algermissen
Jan Algermissen

Reputation: 4978

The best thing to do is likely to apply your own server-side weight if there are types with the same weight in the accept header. Thus if you have text/html and image/* both with the same q-value (or none) you could give text/html preference by default.

Upvotes: 1

trendels
trendels

Reputation: 4807

I would simply keep a blacklist of programs that send obviously broken Accept headers, like IE and Safari (according to the article). If the User-Agent header matches the blacklist, ignore the Accept header, otherwise don't.

The problem with IEs Accept header is not that it puts image/* at the start, but that it doesn't indicate that it prefers HTML or XHTML over images (via the q parameter). AFAIK, the order of the elements in the Accept header is not significant.

Upvotes: 0

Related Questions