This commit is contained in:
Dão Gottwald 2012-02-22 14:03:03 +01:00
Родитель e8ebe9c53f 8f1d6ed17e
Коммит 0d10fb3778
2 изменённых файлов: 5 добавлений и 56 удалений

Просмотреть файл

@ -468,7 +468,7 @@ TelemetryPing.prototype = {
request.mozBackgroundRequest = true; request.mozBackgroundRequest = true;
request.open("POST", url, true); request.open("POST", url, true);
request.overrideMimeType("text/plain"); request.overrideMimeType("text/plain");
request.setRequestHeader("Content-Type", "application/json; charset=UTF-8"); request.setRequestHeader("Content-Type", "application/json");
let startTime = new Date(); let startTime = new Date();
@ -486,37 +486,9 @@ TelemetryPing.prototype = {
request.addEventListener("error", function(aEvent) finishRequest(request.channel), false); request.addEventListener("error", function(aEvent) finishRequest(request.channel), false);
request.addEventListener("load", function(aEvent) finishRequest(request.channel), false); request.addEventListener("load", function(aEvent) finishRequest(request.channel), false);
request.setRequestHeader("Content-Encoding", "gzip"); request.send(data.payload);
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() { attachObservers: function attachObservers() {
if (!this._initialized) if (!this._initialized)
return; return;

Просмотреть файл

@ -57,31 +57,8 @@ function checkHistograms(request, response) {
// do not need the http server anymore // do not need the http server anymore
httpserver.stop(do_test_finished); httpserver.stop(do_test_finished);
let s = request.bodyInputStream; let s = request.bodyInputStream;
let payload = null; let payload = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON)
let decoder = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON) .decodeFromStream(s, s.available());
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_eq(request.getHeader("content-type"), "application/json; charset=UTF-8");
do_check_true(payload.simpleMeasurements.uptime >= 0); do_check_true(payload.simpleMeasurements.uptime >= 0);