views:

286

answers:

1

I am trying to debug an issue on my server side and I believe it has to do with the accept headers that are being sent from the browser. Here is my question, why would Internet Explorer change "accept" headers from one page to another page? Can I change the request headers from javascript?

Here is a request from one page:

Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-application, application/x-shockwave-flash, */*

Here is a request from another page:

Accept: */*

They are all GET requests and I see any major differences between the content. All served from the same application server (Websphere).

+3  A: 

IE's Accept headers

According to this blog post from an IE developer, IE is "inconsistent" with its Accept headers. It explains that the extra values you see come from a registry key to which which applications can add their content types, but does not explain why the values from this registry key are not always used:

However, in some navigations, you’ll see that IE sends a more complete string, containing a wide variety of MIME-types. For instance:

image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/msword, application/vnd.ms-excel, application/x-shockwave-flash, */*

Hit F5 to refresh that page, and IE will probably go back to sending / again. Clearly, IE is inconsistent in what it chooses to send in the Accept header, but by now you’re probably curious where these MIME types even come from.

IE generates this list by enumerating the values listed in the following registry key:

HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Accepted Documents

Knowing this probably doesn't really solve your problem. But notice that */* still occurs in both Accept headers, so as far as content negotiation is concerned there should be no problem here. However, the extra types added to the header could be making the request too large, so that might give you a clue about where to start looking.

Modifying request headers with JavaScript

You can modify the headers of asynchronous (XMLHttpRequest) requests using XMLHttpRequest.setRequestHeader() method, described on this page.

Also see this question: http://stackoverflow.com/questions/581383/adding-custom-http-headers-using-javascript

Disclaimer: I have not tried using this for Accept headers.

If the requests you want to control are not AJAX requests, however, I'm not aware of any way you can modify these with JavaScript.

Sorry that I've not been able to provide complete answers to both of your questions, but I hope the information I've given is helpful.

Ben James
No, it was good. Thanks.
Berlin Brown