Allow to set content type in the plugin REST API interface

The REST API interface for plugins provided by the PolyGerrit UI, was
only able to send bodies in JSON format. Since some REST API endpoints
required plain text, not all endpoints could be called from the UI.

This change adds a parameter to the post- and put-methods of the plugin
REST API interface, that allows to optionally set the content type of
the body. By default it continues to be JSON.

To provide the same API-syntax as the core REST Api interface, an
optional error function can also be given to the post- and put-requests.

Change-Id: Iafe7ca762270832923a14e96c281cf021d5ead63
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-rest-api.js b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-rest-api.js
index eb0c7e0..76e200e 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-rest-api.js
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-plugin-rest-api.js
@@ -52,9 +52,9 @@
    * @return {!Promise}
    */
   GrPluginRestApi.prototype.fetch = function(method, url, opt_payload,
-      opt_errFn) {
+      opt_errFn, opt_contentType) {
     return getRestApi().send(method, this.opt_prefix + url, opt_payload,
-        opt_errFn);
+        opt_errFn, opt_contentType);
   };
 
   /**
@@ -67,20 +67,21 @@
    * @return {!Promise} resolves on success, rejects on error.
    */
   GrPluginRestApi.prototype.send = function(method, url, opt_payload,
-      opt_errFn) {
-    return this.fetch(method, url, opt_payload, opt_errFn).then(response => {
-      if (response.status < 200 || response.status >= 300) {
-        return response.text().then(text => {
-          if (text) {
-            return Promise.reject(text);
+      opt_errFn, opt_contentType) {
+    return this.fetch(method, url, opt_payload, opt_errFn, opt_contentType)
+        .then(response => {
+          if (response.status < 200 || response.status >= 300) {
+            return response.text().then(text => {
+              if (text) {
+                return Promise.reject(text);
+              } else {
+                return Promise.reject(response.status);
+              }
+            });
           } else {
-            return Promise.reject(response.status);
+            return getRestApi().getResponseObject(response);
           }
         });
-      } else {
-        return getRestApi().getResponseObject(response);
-      }
-    });
   };
 
   /**
@@ -95,16 +96,18 @@
    * @param {string} url URL without base path or plugin prefix
    * @return {!Promise} resolves on success, rejects on error.
    */
-  GrPluginRestApi.prototype.post = function(url, opt_payload) {
-    return this.send('POST', url, opt_payload);
+  GrPluginRestApi.prototype.post = function(url, opt_payload, opt_errFn,
+      opt_contentType) {
+    return this.send('POST', url, opt_payload, opt_errFn, opt_contentType);
   };
 
   /**
    * @param {string} url URL without base path or plugin prefix
    * @return {!Promise} resolves on success, rejects on error.
    */
-  GrPluginRestApi.prototype.put = function(url, opt_payload) {
-    return this.send('PUT', url, opt_payload);
+  GrPluginRestApi.prototype.put = function(url, opt_payload, opt_errFn,
+      opt_contentType) {
+    return this.send('PUT', url, opt_payload, opt_errFn, opt_contentType);
   };
 
   /**