PDA

View Full Version : [CLOSED] JSON proxy does not set correct accept header



alexander.urban
11 Dec 2013, 6:33 AM
Consider a JSON proxy



proxy : {
type : 'ajax',
noCache: false,
...
api: {
read : '/ms/web/api/Call',
...
},

reader : {
type : 'json',
root: 'rootNode'
},


The MS Web API call handler function looks like


function Call(int param1,int param2=1) {
...
return someObject;
}

The thing is the "return someObject" line. At that point, MS Web API determines automatically what result the user expects by evaluating the Accept Header sent with the request, and, if possible, returns the object in a serialization format that the client can handle.

Unfortunately, it seems extJS proxy does not set the accept header correctly. IMO you have to set "application/json" for every ajax request from a json proxy.

So, if I did not overlook an additional option _I_ have to set in my ExtJS proxy to achieve the desired result, ExtJS has a bug here.

evant
11 Dec 2013, 10:00 AM
Not really sure why you say there's a bug here.

In your code, you didn't specify any headers, so they won't get forwarded to the request.

http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.proxy.Ajax-cfg-headers

alexander.urban
12 Dec 2013, 12:58 AM
Is there any reason why one would use a proxy with json reader with any other accept-header than "application/json"?If I set my reader to type json, shouldn't I expect the proxy to explicitly request json from the server?As you say it isn't a bug, consider it an improvement.

evant
12 Dec 2013, 5:18 PM
Possibly, but I don't think we should be attempting to force that on people.