Add the "readWithPOST" boolean option to OpenLayers.HTTP. If "readWithPOST" is true then read operations are done using POST requests instead of GET. This is useful when one needs to send lots of data as part of the request. p=aabt, r=crschmidt,me (closes #1917)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@8797 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2009-01-30 16:24:38 +00:00
parent f4c0923bf5
commit a107ab04e4
2 changed files with 120 additions and 7 deletions

View File

@@ -55,6 +55,13 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
*/
scope: null,
/**
* Property: readWithPOST
* {Boolean} true if read operations are done with POST requests
* instead of GET, defaults to false.
*/
readWithPOST: false,
/**
* Constructor: OpenLayers.Protocol.HTTP
* A class for giving layers generic HTTP protocol.
@@ -120,6 +127,7 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
* serialized according to the OpenSearch Geo extension
* (bbox=minx,miny,maxx,maxy). Note that a BBOX filter as the child
* of a logical filter will not be serialized.
* readWithPOST - {Boolean} If the request should be done with POST.
*
* Returns:
* {<OpenLayers.Protocol.Response>} A response object, whose "priv" property
@@ -129,8 +137,10 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
*/
read: function(options) {
options = OpenLayers.Util.applyDefaults(options, this.options);
var readWithPOST = (options.readWithPOST !== undefined) ?
options.readWithPOST : this.readWithPOST;
var resp = new OpenLayers.Protocol.Response({requestType: "read"});
if(options.filter && options.filter instanceof OpenLayers.Filter.Spatial) {
if(options.filter.type == OpenLayers.Filter.Spatial.BBOX) {
options.params = OpenLayers.Util.extend(options.params, {
@@ -139,12 +149,23 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, {
}
}
resp.priv = OpenLayers.Request.GET({
url: options.url,
callback: this.createCallback(this.handleRead, resp, options),
params: options.params,
headers: options.headers
});
if(readWithPOST) {
resp.priv = OpenLayers.Request.POST({
url: options.url,
callback: this.createCallback(this.handleRead, resp, options),
data: OpenLayers.Util.getParameterString(options.params),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
});
} else {
resp.priv = OpenLayers.Request.GET({
url: options.url,
callback: this.createCallback(this.handleRead, resp, options),
params: options.params,
headers: options.headers
});
}
return resp;
},