aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js/modules
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2024-02-16 14:27:00 +0100
committerGitHub <noreply@github.com>2024-02-16 13:27:00 +0000
commitc40ee6fb7382bc2d1398dc685f98a0277d3bfb68 (patch)
tree0db73cf327d9442911a26034a24b52ff45ad49da /web_src/js/modules
parentf2d5c6eddedb75f49af614e362b6f8b1317e3f5d (diff)
downloadgitea-c40ee6fb7382bc2d1398dc685f98a0277d3bfb68.tar.gz
gitea-c40ee6fb7382bc2d1398dc685f98a0277d3bfb68.zip
Refactor request function (#29187)
- Remove and prevent use of `body` argument, it is not used anywhere - Remove uppercasing of method, we can require it to be uppercase
Diffstat (limited to 'web_src/js/modules')
-rw-r--r--web_src/js/modules/fetch.js20
1 files changed, 9 insertions, 11 deletions
diff --git a/web_src/js/modules/fetch.js b/web_src/js/modules/fetch.js
index b3529d27fc..2191a8d4db 100644
--- a/web_src/js/modules/fetch.js
+++ b/web_src/js/modules/fetch.js
@@ -8,19 +8,17 @@ const safeMethods = new Set(['GET', 'HEAD', 'OPTIONS', 'TRACE']);
// fetch wrapper, use below method name functions and the `data` option to pass in data
// which will automatically set an appropriate headers. For json content, only object
// and array types are currently supported.
-export function request(url, {method = 'GET', headers = {}, data, body, ...other} = {}) {
- let contentType;
- if (!body) {
- if (data instanceof FormData || data instanceof URLSearchParams) {
- body = data;
- } else if (isObject(data) || Array.isArray(data)) {
- contentType = 'application/json';
- body = JSON.stringify(data);
- }
+export function request(url, {method = 'GET', data, headers = {}, ...other} = {}) {
+ let body, contentType;
+ if (data instanceof FormData || data instanceof URLSearchParams) {
+ body = data;
+ } else if (isObject(data) || Array.isArray(data)) {
+ contentType = 'application/json';
+ body = JSON.stringify(data);
}
const headersMerged = new Headers({
- ...(!safeMethods.has(method.toUpperCase()) && {'x-csrf-token': csrfToken}),
+ ...(!safeMethods.has(method) && {'x-csrf-token': csrfToken}),
...(contentType && {'content-type': contentType}),
});
@@ -31,8 +29,8 @@ export function request(url, {method = 'GET', headers = {}, data, body, ...other
return fetch(url, {
method,
headers: headersMerged,
- ...(body && {body}),
...other,
+ ...(body && {body}),
});
}