Neuromancer [Re]Addition

A while back I need to do a standard form POST via Neuromancer, so I'd added a doFormPostRequest method to the JSRemote object.  I just needed it again, and for whatever reason, it hadn't made it's way into the core distribution.  So I merged my modded sources in (I love version control ; )), and thought I'd share.

As before, the updates are in the Subversion repo, or you may use the patch below.  Note that this time it's for js/io/Gateway.js, not RemoteObject.js.

Index: Gateway.js
===================================================================
— Gateway.js (revision 8)
+++ Gateway.js (revision 9)
@@ -161,6 +161,38 @@
};

/**
+ * Method: JSRemote.doFormPostRequest
+ * This method implements a multi-field form submission via a POST,
+ * using the 'fields' object as a set of name:value pairs to pass as
+ * the form fields. It simply delegates to doPostRequest for the
+ * actual processing; the only functionality is serializing the fields.
+ *
+ * Note that this method's parameter ordering does NOT correspond to
+ * doPostRequest's.
+ *
+ * Parameters:
+ * url – the url to POST to
+ * fields – the form fields to POST
+ * handler – the callback function to send results to
+ */
+JSRemote.prototype.doFormPostRequest = function _doFormPostRequest(url, fields, handler) {
+ var body = "";
+ var headers = new Object();
+ var boundary = "neuro" + Math.random();
+
+ for (var i in fields) {
+ body += "–" + boundary + "\nContent-Disposition: form-data;name=\"" + i + "\"\n";
+ body += "\n";
+ body += fields[i] + "\n";
+ body += "\n";
+ }
+ body += "–" + boundary + "–";
+
+ headers["Content-Type"] = "multipart/form-data; boundary=" + boundary;
+ this.doPostRequest(url, handler, body, headers);
+}
+
+/**
* Method: JSRemote.doPostRequest
* Does a simple post request, passing the bodyinfo as the body of the
* request – meaning the only way to get the bodyinfo out is to do
@@ -171,7 +203,7 @@
* func_handler – the callback function to send the results to
* bodyinfo – what to send in the body of the POST
*/
-JSRemote.prototype.doPostRequest = function _doPostRequest(url, func_handler, bodyinfo)
+JSRemote.prototype.doPostRequest = function _doPostRequest(url, func_handler, bodyinfo, extraHeaders)
{
log.info("doPostRequest to " + url);
log.info("using pipe: " + this.connectionid);
@@ -211,6 +243,11 @@
conn.setRequestHeader("XLibrary", "Neuromancer 1.5beta");
if(bodyinfo.indexOf("

Comments are closed.