Opera Technology Preview 9 and XMLHttpRequest http headers

Michael Schwarz on Wednesday, November 2, 2005

Update: I get one request for the favicon.ico on every XMLHttpRequest request, that is strange, too.

If you are using the XMLHttpRequest object you have to be careful for the .setRequestHeader method. To override header values in Opera 9 you have to use the exact name of the header.

xmlhttp.setRequestHeader("Content-type", "abc");

The example above will add a new header to the list:

Content-type: abc Content-Type: text/xml; charset=utf-8    (the default)

Another example is this:

xmlhttp.setRequestHeader("Content-type", "abc"); xmlhttp.setRequestHeader("content-type", "test");

You will have still have only two headers for the content type, you get this http request now:

Content-type: abc, test Content-Type: text/xml; charset=utf-8    (the default)

If you use case sensitive key names in your JavaScript code the XMLHttpRequest is working correct. To override the built-in headers you have to use the same notation:

xmlhttp.setRequestHeader("Content-Type", "abc"); xmlhttp.setRequestHeader("Content-Type", "test");

Now, you have only one http header for the content type, the default value is missing:

Content-Type: abc, test