mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
Bug 717061 - compress telemetry pings; r=taras
This commit is contained in:
parent
99a72f5964
commit
0157a5ecb4
@ -468,7 +468,7 @@ TelemetryPing.prototype = {
|
||||
request.mozBackgroundRequest = true;
|
||||
request.open("POST", url, true);
|
||||
request.overrideMimeType("text/plain");
|
||||
request.setRequestHeader("Content-Type", "application/json");
|
||||
request.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
|
||||
|
||||
let startTime = new Date();
|
||||
|
||||
@ -486,9 +486,37 @@ TelemetryPing.prototype = {
|
||||
request.addEventListener("error", function(aEvent) finishRequest(request.channel), false);
|
||||
request.addEventListener("load", function(aEvent) finishRequest(request.channel), false);
|
||||
|
||||
request.send(data.payload);
|
||||
request.setRequestHeader("Content-Encoding", "gzip");
|
||||
let payloadStream = Cc["@mozilla.org/io/string-input-stream;1"]
|
||||
.createInstance(Ci.nsIStringInputStream);
|
||||
payloadStream.data = this.gzipCompressString(data.payload);
|
||||
request.send(payloadStream);
|
||||
},
|
||||
|
||||
|
||||
gzipCompressString: function gzipCompressString(string) {
|
||||
let observer = {
|
||||
buffer: "",
|
||||
onStreamComplete: function(loader, context, status, length, result) {
|
||||
this.buffer = String.fromCharCode.apply(this, result);
|
||||
}
|
||||
};
|
||||
|
||||
let scs = Cc["@mozilla.org/streamConverters;1"]
|
||||
.getService(Ci.nsIStreamConverterService);
|
||||
let listener = Cc["@mozilla.org/network/stream-loader;1"]
|
||||
.createInstance(Ci.nsIStreamLoader);
|
||||
listener.init(observer);
|
||||
let converter = scs.asyncConvertData("uncompressed", "gzip",
|
||||
listener, null);
|
||||
let stringStream = Cc["@mozilla.org/io/string-input-stream;1"]
|
||||
.createInstance(Ci.nsIStringInputStream);
|
||||
stringStream.data = string;
|
||||
converter.onStartRequest(null, null);
|
||||
converter.onDataAvailable(null, null, stringStream, 0, string.length);
|
||||
converter.onStopRequest(null, null, null);
|
||||
return observer.buffer;
|
||||
},
|
||||
|
||||
attachObservers: function attachObservers() {
|
||||
if (!this._initialized)
|
||||
return;
|
||||
|
@ -57,8 +57,31 @@ function checkHistograms(request, response) {
|
||||
// do not need the http server anymore
|
||||
httpserver.stop(do_test_finished);
|
||||
let s = request.bodyInputStream;
|
||||
let payload = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON)
|
||||
.decodeFromStream(s, s.available());
|
||||
let payload = null;
|
||||
let decoder = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON)
|
||||
|
||||
if (request.getHeader("content-encoding") == "gzip") {
|
||||
let observer = {
|
||||
buffer: "",
|
||||
onStreamComplete: function(loader, context, status, length, result) {
|
||||
this.buffer = String.fromCharCode.apply(this, result);
|
||||
}
|
||||
};
|
||||
|
||||
let scs = Cc["@mozilla.org/streamConverters;1"]
|
||||
.getService(Ci.nsIStreamConverterService);
|
||||
let listener = Cc["@mozilla.org/network/stream-loader;1"]
|
||||
.createInstance(Ci.nsIStreamLoader);
|
||||
listener.init(observer);
|
||||
let converter = scs.asyncConvertData("gzip", "uncompressed",
|
||||
listener, null);
|
||||
converter.onStartRequest(null, null);
|
||||
converter.onDataAvailable(null, null, s, 0, s.available());
|
||||
converter.onStopRequest(null, null, null);
|
||||
payload = decoder.decode(observer.buffer);
|
||||
} else {
|
||||
payload = decoder.decodeFromStream(s, s.available());
|
||||
}
|
||||
|
||||
do_check_eq(request.getHeader("content-type"), "application/json; charset=UTF-8");
|
||||
do_check_true(payload.simpleMeasurements.uptime >= 0);
|
||||
|
Loading…
Reference in New Issue
Block a user