Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/downloader.js

Issue 29336735: Issue 394 - hit statistics tool data collection (core) (Closed)
Patch Set: Use Downloader to send the data to server Created April 6, 2016, 2:55 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/filterListener.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/downloader.js
===================================================================
--- a/lib/downloader.js
+++ b/lib/downloader.js
@@ -115,6 +115,18 @@
onDownloadError: null,
/**
+ * Callback to be triggered for POST request data generation.
+ * @type Function
+ */
+ generateRequestData: null,
+
+ /**
+ * List of valid responses.
+ * @type Array
+ */
+ validResponses: [200],
+
+ /**
* Checks whether anything needs downloading.
*/
_doCheck: function()
@@ -250,7 +262,7 @@
{
request = new XMLHttpRequest();
request.mozBackgroundRequest = true;
- request.open("GET", downloadUrl);
+ request.open(this.generateRequestData ? "POST" : "GET", downloadUrl);
}
catch (e)
{
@@ -290,7 +302,7 @@
delete this._downloading[downloadable.url];
// Status will be 0 for non-HTTP requests
- if (request.status && request.status != 200)
+ if (request.status && this.validResponses.indexOf(request.status) == -1)
{
errorCallback("synchronize_connection_error");
return;
@@ -310,7 +322,16 @@
}.bind(this));
}.bind(this), false);
- request.send(null);
+ if (this.generateRequestData)
+ {
+ Promise.resolve(this.generateRequestData(downloadable))
+ .then(data => {
+ request.setRequestHeader("Content-Type", "application/json");
+ request.send(JSON.stringify(data));
+ });
+ }
+ else
+ request.send(null);
this._downloading[downloadable.url] = true;
if (this.onDownloadStarted)
« no previous file with comments | « no previous file | lib/filterListener.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld