HTTP protocol: enable POST for update/delete

This commit is contained in:
Peter Robins
2012-02-08 11:20:06 +00:00
parent e7eae00246
commit 9732cf77aa
+25 -4
View File
@@ -62,12 +62,27 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
scope: null, scope: null,
/** /**
* Property: readWithPOST * APIProperty: readWithPOST
* {Boolean} true if read operations are done with POST requests * {Boolean} true if read operations are done with POST requests
* instead of GET, defaults to false. * instead of GET, defaults to false.
*/ */
readWithPOST: false, readWithPOST: false,
/**
* APIProperty: updateWithPOST
* {Boolean} true if update operations are done with POST requests
* defaults to false.
*/
updateWithPOST: false,
/**
* APIProperty: deleteWithPOST
* {Boolean} true if delete operations are done with POST requests
* defaults to false.
* if true, POST data is set to output of format.write().
*/
deleteWithPOST: false,
/** /**
* Property: wildcarded. * Property: wildcarded.
* {Boolean} If true percent signs are added around values * {Boolean} If true percent signs are added around values
@@ -293,7 +308,8 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
requestType: "update" requestType: "update"
}); });
resp.priv = OpenLayers.Request.PUT({ var method = this.updateWithPOST ? "POST" : "PUT";
resp.priv = OpenLayers.Request[method]({
url: url, url: url,
callback: this.createCallback(this.handleUpdate, resp, options), callback: this.createCallback(this.handleUpdate, resp, options),
headers: options.headers, headers: options.headers,
@@ -344,11 +360,16 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
requestType: "delete" requestType: "delete"
}); });
resp.priv = OpenLayers.Request.DELETE({ var method = this.deleteWithPOST ? "POST" : "DELETE";
var requestOptions = {
url: url, url: url,
callback: this.createCallback(this.handleDelete, resp, options), callback: this.createCallback(this.handleDelete, resp, options),
headers: options.headers headers: options.headers
}); };
if (this.deleteWithPOST) {
requestOptions.data = this.format.write(feature);
}
resp.priv = OpenLayers.Request[method](requestOptions);
return resp; return resp;
}, },