Bug 838461 - Improve rest.js interop with FHR; r=rnewman
authorGregory Szorc <gps@mozilla.com>
Tue, 05 Feb 2013 20:25:57 -0800
changeset 120940 1ed20e6b41c2be5467bab8e2f0709f6a5ff67c28
parent 120939 42abb7556fd9fbe1de3ac897b62e651863d104f5
child 120941 65e0a461f1eff292c87ba4c4336c0571172524c7
push id24268
push usergszorc@mozilla.com
push dateWed, 06 Feb 2013 06:42:42 +0000
treeherdermozilla-central@bc108d2ce8d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs838461
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 838461 - Improve rest.js interop with FHR; r=rnewman
services/common/bagheeraclient.js
--- a/services/common/bagheeraclient.js
+++ b/services/common/bagheeraclient.js
@@ -15,59 +15,75 @@
 
 this.EXPORTED_SYMBOLS = [
   "BagheeraClient",
   "BagheeraClientRequestResult",
 ];
 
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
-Cu.import("resource://services-common/rest.js");
 #endif
 
 Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js");
 Cu.import("resource://services-common/log4moz.js");
+Cu.import("resource://services-common/rest.js");
 Cu.import("resource://services-common/utils.js");
 
 
 /**
  * Represents the result of a Bagheera request.
  */
 this.BagheeraClientRequestResult = function BagheeraClientRequestResult() {
   this.transportSuccess = false;
   this.serverSuccess = false;
   this.request = null;
+};
+
+Object.freeze(BagheeraClientRequestResult.prototype);
+
+
+/**
+ * Wrapper around RESTRequest so logging is sane.
+ */
+function BagheeraRequest(uri) {
+  RESTRequest.call(this, uri);
+
+  this._log = Log4Moz.repository.getLogger("Services.BagheeraClient");
+  this._log.level = Log4Moz.Level.Debug;
 }
 
-Object.freeze(BagheeraClientRequestResult.prototype);
+BagheeraRequest.prototype = Object.freeze({
+  __proto__: RESTRequest.prototype,
+});
+
 
 /**
  * Create a new Bagheera client instance.
  *
  * Each client is associated with a specific Bagheera HTTP URI endpoint.
  *
  * @param baseURI
  *        (string) The base URI of the Bagheera HTTP endpoint.
  */
 this.BagheeraClient = function BagheeraClient(baseURI) {
   if (!baseURI) {
     throw new Error("baseURI argument must be defined.");
   }
 
   this._log = Log4Moz.repository.getLogger("Services.BagheeraClient");
-  this._log.level = Log4Moz.Level["Debug"];
+  this._log.level = Log4Moz.Level.Debug;
 
   this.baseURI = baseURI;
 
   if (!baseURI.endsWith("/")) {
     this.baseURI += "/";
   }
-}
+};
 
-BagheeraClient.prototype = {
+BagheeraClient.prototype = Object.freeze({
   /**
    * Channel load flags for all requests.
    *
    * Caching is not applicable, so we bypass and disable it. We also
    * ignore any cookies that may be present for the domain because
    * Bagheera does not utilize cookies and the release of cookies may
    * inadvertantly constitute unncessary information disclosure.
    */
@@ -123,17 +139,17 @@ BagheeraClient.prototype = {
     }
 
     if (typeof(data) != "string") {
       throw new Error("Unknown type for payload: " + typeof(data));
     }
 
     this._log.info("Uploading data to " + uri);
 
-    let request = new RESTRequest(uri);
+    let request = new BagheeraRequest(uri);
     request.loadFlags = this._loadFlags;
     request.timeout = this.DEFAULT_TIMEOUT_MSEC;
 
     if (deleteOldID) {
       request.setHeader("X-Obsolete-Document", deleteOldID);
     }
 
     let deferred = Promise.defer();
@@ -162,17 +178,17 @@ BagheeraClient.prototype = {
    * @param id
    *        (string) ID of document to delete.
    *
    * @return Promise<BagheeraClientRequestResult>
    */
   deleteDocument: function deleteDocument(namespace, id) {
     let uri = this._submitURI(namespace, id);
 
-    let request = new RESTRequest(uri);
+    let request = new BagheeraRequest(uri);
     request.loadFlags = this._loadFlags;
     request.timeout = this.DEFAULT_TIMEOUT_MSEC;
 
     let result = new BagheeraClientRequestResult();
     result.namespace = namespace;
     result.id = id;
     let deferred = Promise.defer();
 
@@ -220,11 +236,10 @@ BagheeraClient.prototype = {
         result.serverSuccess = false;
 
         this._log.info("Received unexpected status code: " + response.status);
         this._log.debug("Response body: " + response.body);
     }
 
     deferred.resolve(result);
   },
-};
+});
 
-Object.freeze(BagheeraClient.prototype);