PDA

View Full Version : [FIXED-1053][Ext 3.0.2] Ajax headers and Webkit/Safari Issue



elDub
9 Jun 2010, 11:32 AM
I am setting the default headers for my Ajax request with:


Ext.lib.Ajax.defaultHeaders = { accept: "application/json" };
and then specifying a header in a particular Ajax request like:


Ext.Ajax.request({
headers: {
accept: "application/ext-component"
},
...
});
The problem is that I am getting two different results from two different browsers.

Firefox 3.6.3 (Mac) generates a header of:


Accept: application/ext-component
and Safari 5.0 and Chrome 5.0.375.70 (both on a Mac) generate it as:



Accept: application/json, application/ext-component
which is a problem because the server is responding with content typed as application/json rather than application/ext-component. What am I doing wrong here, or what can I do to fix this?

jsakalos
10 Jun 2010, 2:20 AM
I would bet that this is browser specific behavior. Anyway, I'm moving this thread to bugs so that devel-team takes a look and explains/fixes the issue.

evant
10 Jun 2010, 2:48 AM
Pretty trivial to test:



var http = new XMLHttpRequest();
http.open('GET', 'data.asp', true)
http.setRequestHeader('accept', 'application/json');
http.setRequestHeader('accept', 'application/ext-component');
http.send('x');


For some reason Chrome/WebKit acts differently.

evant
10 Jun 2010, 2:54 AM
http://groups.google.com/a/chromium.org/group/chromium-bugs/msg/29a95e60bf971055

evant
10 Jun 2010, 3:13 AM
It seems the implementation in Chrome/Safari is correct: http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method

However IE, Opera and FF all have the same "incorrect" behaviour.

elDub
10 Jun 2010, 5:30 AM
If Webkit is doing it correctly, should the following ext-base code be altered from:


Ext.lib.Ajax = function() {
...
function setHeader(o) {
...
if (pub.defaultHeaders) {
setTheHeaders(conn, pub.defaultHeaders);
}
if (pub.headers) {
setTheHeaders(conn, pub.headers);
delete pub.headers;
}
...
}
...
}

to:


Ext.lib.Ajax = function() {
...
function setHeader(o) {
...
if (pub.defaultHeaders || pub.headers){
if (pub.headers){
var mergedHeaders = {};
Ext.apply(mergedHeaders, pub.defaultHeaders || {});
Ext.apply(mergedHeaders, pub.headers);
setTheHeaders(conn, mergedHeaders);
delete pub.headers;
}else{
setTheHeaders(conn, pub.defaultHeaders);
}
}
...
}
...
}


Does that properly reflect the intentions of the relationship between the Ext.lib.Ajax.defaultHeaders (or Ext.Ajax.defaultHeaders) object any any specified headers object for an actual Ajax call?

evant
10 Jun 2010, 5:45 AM
Well... should it? As far as I can see Chrome/Safari is correct, but everything else overwrites the property. At this point I'd prefer to not modify the behaviour.

elDub
10 Jun 2010, 5:56 AM
Now I wasn't the developer of Ext.lib.Ajax, but if I take what has been happening up until recent builds of Webkit (which you say is doing things correctly according to the standards), the relationship between defaultHeaders and an explicit headers declaration was that the explicit would overwrite anything specified in the defaultHeaders. Since we cannot modify XMLHttpRequest#setRequestHeader(), we need to change how we interact with it. That is what my suggested code is intended to do.

MaximGB
11 Jun 2010, 7:45 AM
Also if one wants multiple entries in accept header he/she would write it like that


Ext.Ajax.request({
headers: {
accept: "application/json, application/ext-component"
},
...
});


As for me specific setting must overwrite the default one.

elDub
15 Jun 2010, 5:01 AM
I agree with you MaximGB.

Evan, should this be marked as a bug then?

evant
15 Jun 2010, 5:07 AM
Yeah, I guess. The intent is that specific settings should overwrite defaults. The problem was it was relying on the (seemingly incorrect) behaviour of non chrome-safari browsers.

evant
15 Jun 2010, 7:21 AM
A fix has been added to SVN, it will be part of 3.3.