PDA

View Full Version : [3.2.1] Request params might be handled incorrectly in HttpProxy#doRequest



feiichi
22 Sep 2010, 3:18 AM
Consider the following code in HttpProxy#doRequest:

if (params.jsonData) {
o.jsonData = params.jsonData;
} else if (params.xmlData) {
o.xmlData = params.xmlData;
} else {
o.params = params || {};
}

Now imagine you use JsonWriter or XmlWriter and want to either PUT, POST, or DELETE record(s). If you use the XmlWriter or set the "encode" parameter of JsonWriter to false, the jsonData or xmlData of the params object are being transmitted to the Ext.Ajax.Request and dealt with accordingly to the request method.

The problem rises when you want to add some extra parameters to the PUT, POST or DELETE request since any extra parameters are now being omitted in the case jsonData or xmlData is present in the params object.

Use case: you are performing one of the create, update, delete actions on a store and you need to send additional parameters to the server as a part of the URL aside the jsonData or xmlData object (which is what Ext.Ajax.Request permits and can handle), so you make an event handler for the beforewrite event of DataProxy which enables you to modify the params object with additional configuration but the configuration is then ommited and hacking the jsonData or xmlData object isn't possible either since they don't make it through a DELETE request (which is ok ofc).

I think a more appropriate handling of the params object would be perhaps something like this?

if (params.jsonData) {
o.jsonData = params.jsonData;
delete params.jsonData;
} else if (params.xmlData) {
o.xmlData = params.xmlData;
delete params.xmlData;
}
o.params = params || {};