summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorMichael Mattiello (mcm) <mcm@odoo.com>2020-04-14 08:04:09 +0000
committerMichael Mattiello (mcm) <mcm@odoo.com>2020-05-27 12:26:05 +0000
commitb110bd4cbef272f311680ce8cba39b727b2d6c42 (patch)
treeb73125fc76352024dbbd811371b76f2ac8f1f1f4 /addons
parentcf90b56c3cd8a8a7012cded0cf7690fc63e3190f (diff)
[FIX] web: fix httpRequest GET + add in test_env
This commit fixes the method GET in httpRequest and adds it in test_env. Before this commit, the GET method crashed because of the forced body param. closes odoo/odoo#51980 X-original-commit: 7c4fba660a13c38048020faf595bd348d1bca225 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/web/static/src/js/env.js33
-rw-r--r--addons/web/static/tests/helpers/test_env.js3
2 files changed, 21 insertions, 15 deletions
diff --git a/addons/web/static/src/js/env.js b/addons/web/static/src/js/env.js
index 272a1f77ead..c95cbd3045a 100644
--- a/addons/web/static/src/js/env.js
+++ b/addons/web/static/src/js/env.js
@@ -22,25 +22,28 @@ odoo.define("web.env", function (require) {
}
function httpRequest(route, params = {}, readMethod = 'json') {
- const formData = new FormData();
- for (const key in params) {
- if (key === 'method') {
- continue;
- }
- const value = params[key];
- if (Array.isArray(value) && value.length) {
- for (const val of value) {
- formData.append(key, val);
+ const info = {
+ method: params.method || 'POST',
+ };
+ if (params.method !== 'GET') {
+ const formData = new FormData();
+ for (const key in params) {
+ if (key === 'method') {
+ continue;
+ }
+ const value = params[key];
+ if (Array.isArray(value) && value.length) {
+ for (const val of value) {
+ formData.append(key, val);
+ }
+ } else {
+ formData.append(key, value);
}
- } else {
- formData.append(key, value);
}
+ info.body = formData;
}
- return fetch(route, {
- method: params.method || 'POST',
- body: formData,
- }).then(response => response[readMethod]());
+ return fetch(route, info).then(response => response[readMethod]());
}
function navigate(url, params) {
diff --git a/addons/web/static/tests/helpers/test_env.js b/addons/web/static/tests/helpers/test_env.js
index b61024454ed..5b197451517 100644
--- a/addons/web/static/tests/helpers/test_env.js
+++ b/addons/web/static/tests/helpers/test_env.js
@@ -49,6 +49,9 @@ odoo.define('web.test_env', async function (require) {
},
},
getCookie() { },
+ httpRequest() {
+ return Promise.resolve('');
+ },
rpc(params, options) {
const query = buildQuery(params);
return testEnv.session.rpc(query.route, query.params, options);