From 7272663e8d5cd6e1dced63a5432a7a8570435e2e Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 15 Sep 2018 17:13:56 +0200 Subject: [PATCH] Fix bugs after live tests --- Message/Request/Request.js | 33 +++++++++++++++++++++++++++------ Message/Request/RequestType.js | 3 ++- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Message/Request/Request.js b/Message/Request/Request.js index d3f3128..9c3b7cf 100644 --- a/Message/Request/Request.js +++ b/Message/Request/Request.js @@ -25,9 +25,11 @@ this.method = typeof method !== 'undefined' ? method : jsOMS.Message.Request.RequestMethod.GET; this.requestHeader = []; this.result = {}; - this.type = typeof type !== 'undefined' ? type : jsOMS.Message.Response.ResponseType.JSON; + this.type = typeof type !== 'undefined' ? type : jsOMS.Message.Request.RequestType.JSON; this.data = {}; + this.requestHeader['Content-Type'] = this.setContentTypeBasedOnType(this.type); + // todo: create log; this.result[0] = function() { @@ -38,6 +40,27 @@ this.xhr = new XMLHttpRequest(); }; + /** + * Defines the request content type based on the type + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + setContentTypeBasedOnType(type) + { + switch(type) { + case jsOMS.Message.Request.RequestType.JSON: + return 'application/json'; + case jsOMS.Message.Request.RequestType.URL_ENCODE: + return 'application/x-www-form-urlencoded'; + default: + return 'text/plain'; + } + }; + /** * Get browser. * @@ -370,13 +393,11 @@ }; if (this.type === jsOMS.Message.Request.RequestType.JSON) { - if (typeof this.requestHeader !== 'undefined' && this.requestHeader['Content-Type'] === 'application/json') { - this.xhr.send(JSON.stringify(this.data)); - } else { - this.xhr.send(this.queryfy(this.data)); - } + this.xhr.send(JSON.stringify(this.data)); } else if (this.type === jsOMS.Message.Request.RequestType.RAW) { this.xhr.send(this.data); + } else if (this.type === jsOMS.Message.Request.RequestType.URL_ENCODE) { + this.xhr.send(this.queryfy(this.data)); } }; } diff --git a/Message/Request/RequestType.js b/Message/Request/RequestType.js index 5a30cb2..fdb98a4 100644 --- a/Message/Request/RequestType.js +++ b/Message/Request/RequestType.js @@ -15,6 +15,7 @@ jsOMS.Message.Request.RequestType = Object.freeze({ JSON: 'json', - RAW: 'raw' + RAW: 'raw', + URL_ENCODE: 'url' }); }(window.jsOMS = window.jsOMS || {}));