summaryrefslogtreecommitdiffstats
path: root/services/sync/modules/resource.js
diff options
context:
space:
mode:
authorwicknix <39230578+wicknix@users.noreply.github.com>2019-04-15 18:58:07 -0500
committerGitHub <noreply@github.com>2019-04-15 18:58:07 -0500
commit5a1843c9f9e323627f9c35529e6a8c853d4dbb0d (patch)
tree62de3cd7cb8a6f75e568863bb73ca2deb80d87a9 /services/sync/modules/resource.js
parent065f6f9e5ebc1ed6cfaadaf7851b6021fa94a013 (diff)
parent095ea556855b38138e39e713f482eb440f7da9b2 (diff)
downloadUXP-5a1843c9f9e323627f9c35529e6a8c853d4dbb0d.tar
UXP-5a1843c9f9e323627f9c35529e6a8c853d4dbb0d.tar.gz
UXP-5a1843c9f9e323627f9c35529e6a8c853d4dbb0d.tar.lz
UXP-5a1843c9f9e323627f9c35529e6a8c853d4dbb0d.tar.xz
UXP-5a1843c9f9e323627f9c35529e6a8c853d4dbb0d.zip
Merge pull request #1 from MoonchildProductions/master
keep up with mc
Diffstat (limited to 'services/sync/modules/resource.js')
-rw-r--r--services/sync/modules/resource.js65
1 files changed, 37 insertions, 28 deletions
diff --git a/services/sync/modules/resource.js b/services/sync/modules/resource.js
index bf7066b9f..a6c0739b6 100644
--- a/services/sync/modules/resource.js
+++ b/services/sync/modules/resource.js
@@ -13,7 +13,6 @@ var Cr = Components.results;
var Cu = Components.utils;
Cu.import("resource://gre/modules/Preferences.jsm");
-Cu.import("resource://gre/modules/NetUtil.jsm");
Cu.import("resource://services-common/async.js");
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://services-common/observers.js");
@@ -74,6 +73,20 @@ AsyncResource.prototype = {
*/
authenticator: null,
+ // The string to use as the base User-Agent in Sync requests.
+ // These strings will look something like
+ //
+ // Firefox/4.0 FxSync/1.8.0.20100101.mobile
+ //
+ // or
+ //
+ // Firefox Aurora/5.0a1 FxSync/1.9.0.20110409.desktop
+ //
+ _userAgent:
+ Services.appinfo.name + "/" + Services.appinfo.version + // Product.
+ " FxSync/" + WEAVE_VERSION + "." + // Sync.
+ Services.appinfo.appBuildID + ".", // Build.
+
// Wait 5 minutes before killing a request.
ABORT_TIMEOUT: 300000,
@@ -121,9 +134,7 @@ AsyncResource.prototype = {
//
// Get and set the data encapulated in the resource.
_data: null,
- get data() {
- return this._data;
- },
+ get data() this._data,
set data(value) {
this._data = value;
},
@@ -135,9 +146,16 @@ AsyncResource.prototype = {
// to obtain a request channel.
//
_createRequest: function Res__createRequest(method) {
- let channel = NetUtil.newChannel({uri: this.spec, loadUsingSystemPrincipal: true})
- .QueryInterface(Ci.nsIRequest)
- .QueryInterface(Ci.nsIHttpChannel);
+ let channel = Services.io.newChannel2(this.spec,
+ null,
+ null,
+ null, // aLoadingNode
+ Services.scriptSecurityManager.getSystemPrincipal(),
+ null, // aTriggeringPrincipal
+ Ci.nsILoadInfo.SEC_NORMAL,
+ Ci.nsIContentPolicy.TYPE_OTHER)
+ .QueryInterface(Ci.nsIRequest)
+ .QueryInterface(Ci.nsIHttpChannel);
channel.loadFlags |= DEFAULT_LOAD_FLAGS;
@@ -147,7 +165,8 @@ AsyncResource.prototype = {
// Compose a UA string fragment from the various available identifiers.
if (Svc.Prefs.get("sendVersionInfo", true)) {
- channel.setRequestHeader("user-agent", Utils.userAgent, false);
+ let ua = this._userAgent + Svc.Prefs.get("client.type", "desktop");
+ channel.setRequestHeader("user-agent", ua, false);
}
let headers = this.headers;
@@ -209,10 +228,10 @@ AsyncResource.prototype = {
this._log, this.ABORT_TIMEOUT);
channel.requestMethod = action;
try {
- channel.asyncOpen2(listener);
+ channel.asyncOpen(listener, null);
} catch (ex) {
- // asyncOpen2 can throw in a bunch of cases -- e.g., a forbidden port.
- this._log.warn("Caught an error in asyncOpen2", ex);
+ // asyncOpen can throw in a bunch of cases -- e.g., a forbidden port.
+ this._log.warn("Caught an error in asyncOpen: ", ex);
CommonUtils.nextTick(callback.bind(this, ex));
}
},
@@ -259,7 +278,8 @@ AsyncResource.prototype = {
} catch(ex) {
// Got a response, but an exception occurred during processing.
// This shouldn't occur.
- this._log.warn("Caught unexpected exception in _oncomplete", ex);
+ this._log.warn("Caught unexpected exception in _onComplete. ", ex);
+ this._log.debug(CommonUtils.stackTrace(ex));
}
// Process headers. They can be empty, or the call can otherwise fail, so
@@ -298,17 +318,14 @@ AsyncResource.prototype = {
}
} catch (ex) {
this._log.debug("Caught exception visiting headers in _onComplete", ex);
+ this._log.debug(CommonUtils.stackTrace(ex));
}
let ret = new String(data);
- ret.url = channel.URI.spec;
ret.status = status;
ret.success = success;
ret.headers = headers;
- if (!success) {
- this._log.warn(`${action} request to ${ret.url} failed with status ${status}`);
- }
// Make a lazy getter to convert the json response into an object.
// Note that this can cause a parse error to be thrown far away from the
// actual fetch, so be warned!
@@ -384,12 +401,7 @@ Resource.prototype = {
try {
this._doRequest(action, data, callback);
return Async.waitForSyncCallback(cb);
- } catch (ex) {
- if (Async.isShutdownException(ex)) {
- throw ex;
- }
- this._log.warn("${action} request to ${url} failed: ${ex}",
- { action, url: this.uri.spec, ex });
+ } catch(ex) {
// Combine the channel stack with this request stack. Need to create
// a new error object for that.
let error = Error(ex.message);
@@ -543,9 +555,6 @@ ChannelListener.prototype = {
try {
this._onProgress();
} catch (ex) {
- if (Async.isShutdownException(ex)) {
- throw ex;
- }
this._log.warn("Got exception calling onProgress handler during fetch of "
+ req.URI.spec, ex);
this._log.trace("Rethrowing; expect a failure code from the HTTP channel.");
@@ -562,7 +571,7 @@ ChannelListener.prototype = {
try {
CommonUtils.namedTimer(this.abortRequest, this._timeout, this, "abortTimer");
} catch (ex) {
- this._log.warn("Got exception extending abort timer", ex);
+ this._log.warn("Got exception extending abort timer: ", ex);
}
},
@@ -656,14 +665,14 @@ ChannelNotificationListener.prototype = {
}
}
} catch (ex) {
- this._log.error("Error copying headers", ex);
+ this._log.error("Error copying headers: ", ex);
}
// We let all redirects proceed.
try {
callback.onRedirectVerifyCallback(Cr.NS_OK);
} catch (ex) {
- this._log.error("onRedirectVerifyCallback threw!", ex);
+ this._log.error("onRedirectVerifyCallback threw!" + CommonUtils.exceptionStr(ex));
}
}
};