Added content type to status report requests.

This commit is contained in:
dlebu 2016-01-21 08:25:07 -08:00
Родитель 7c4e1bde43
Коммит 87b2ec72f8
4 изменённых файлов: 29 добавлений и 13 удалений

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

@ -10,7 +10,8 @@
"use strict";
var HttpRequester = (function () {
function HttpRequester() {
function HttpRequester(contentType) {
this.contentType = contentType;
}
HttpRequester.prototype.request = function (verb, url, callbackOrRequestBody, callback) {
var requestBody;
@ -30,6 +31,9 @@ var HttpRequester = (function () {
}
};
xhr.open(methodName, url, true);
if (this.contentType) {
xhr.setRequestHeader("Content-Type", this.contentType);
}
xhr.send(requestBody);
};
HttpRequester.prototype.getHttpMethodName = function (verb) {

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

@ -14,17 +14,18 @@ var HttpRequester = require("./httpRequester");
var Sdk = (function () {
function Sdk() {
}
Sdk.getAcquisitionManager = function (callback, userDeploymentKey) {
Sdk.getAcquisitionManager = function (callback, userDeploymentKey, contentType) {
var resolveManager = function (defaultInstance) {
if (userDeploymentKey) {
if (userDeploymentKey || contentType) {
var customConfiguration = {
deploymentKey: userDeploymentKey,
deploymentKey: (userDeploymentKey ? userDeploymentKey : Sdk.DefaultConfiguration.deploymentKey),
serverUrl: Sdk.DefaultConfiguration.serverUrl,
ignoreAppVersion: Sdk.DefaultConfiguration.ignoreAppVersion,
appVersion: Sdk.DefaultConfiguration.appVersion,
clientUniqueId: Sdk.DefaultConfiguration.clientUniqueId
};
var customAcquisitionManager = new AcquisitionManager(new HttpRequester(), customConfiguration);
var requester = new HttpRequester(contentType);
var customAcquisitionManager = new AcquisitionManager(requester, customConfiguration);
callback(null, customAcquisitionManager);
}
else {
@ -66,7 +67,7 @@ var Sdk = (function () {
else {
acquisitionManager.reportStatusDeploy(pkg, status, callback);
}
}, deploymentKey);
}, deploymentKey, "application/json");
}
catch (e) {
callback && callback(new Error("An error occured while reporting the deployment status. " + e), null);
@ -81,7 +82,7 @@ var Sdk = (function () {
else {
acquisitionManager.reportStatusDownload(pkg, callback);
}
}, deploymentKey);
}, deploymentKey, "application/json");
}
catch (e) {
callback && callback(new Error("An error occured while reporting the download status. " + e), null);

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

@ -6,6 +6,13 @@
* XMLHttpRequest-based implementation of Http.Requester.
*/
class HttpRequester implements Http.Requester {
private contentType: string;
constructor(contentType?: string) {
this.contentType = contentType;
}
public request(verb: Http.Verb, url: string, callbackOrRequestBody: Callback<Http.Response> | string, callback?: Callback<Http.Response>): void {
var requestBody: string;
var requestCallback: Callback<Http.Response> = callback;
@ -27,6 +34,9 @@ class HttpRequester implements Http.Requester {
}
};
xhr.open(methodName, url, true);
if (this.contentType) {
xhr.setRequestHeader("Content-Type", this.contentType);
}
xhr.send(requestBody);
}

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

@ -18,18 +18,19 @@ class Sdk {
/**
* Reads the CodePush configuration and creates an AcquisitionManager instance using it.
*/
public static getAcquisitionManager(callback: Callback<AcquisitionManager>, userDeploymentKey?: string): void {
public static getAcquisitionManager(callback: Callback<AcquisitionManager>, userDeploymentKey?: string, contentType?: string): void {
var resolveManager = (defaultInstance: AcquisitionManager): void => {
if (userDeploymentKey) {
if (userDeploymentKey || contentType) {
var customConfiguration: Configuration = {
deploymentKey: userDeploymentKey,
deploymentKey: (userDeploymentKey ? userDeploymentKey : Sdk.DefaultConfiguration.deploymentKey),
serverUrl: Sdk.DefaultConfiguration.serverUrl,
ignoreAppVersion: Sdk.DefaultConfiguration.ignoreAppVersion,
appVersion: Sdk.DefaultConfiguration.appVersion,
clientUniqueId: Sdk.DefaultConfiguration.clientUniqueId
};
var customAcquisitionManager: AcquisitionManager = new AcquisitionManager(new HttpRequester(), customConfiguration);
var requester = new HttpRequester(contentType);
var customAcquisitionManager: AcquisitionManager = new AcquisitionManager(requester, customConfiguration);
callback(null, customAcquisitionManager);
} else {
callback(null, Sdk.DefaultAcquisitionManager);
@ -73,7 +74,7 @@ class Sdk {
else {
acquisitionManager.reportStatusDeploy(pkg, status, callback);
}
}, deploymentKey);
}, deploymentKey, "application/json");
} catch (e) {
callback && callback(new Error("An error occured while reporting the deployment status. " + e), null);
}
@ -91,7 +92,7 @@ class Sdk {
else {
acquisitionManager.reportStatusDownload(pkg, callback);
}
}, deploymentKey);
}, deploymentKey, "application/json");
} catch (e) {
callback && callback(new Error("An error occured while reporting the download status. " + e), null);
}