aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/utils.js
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-06-02 10:34:16 -0700
committerMaximilian Hils <git@maximilianhils.com>2016-06-02 10:34:16 -0700
commit73e494770fe83b41f879d6f068f15c3056c943cf (patch)
treee80b79ff27c3ed149a89f4b2a55741df2779dfe7 /web/src/js/utils.js
parent89fc438e324c359df8b387a39c9e8beab1df54d0 (diff)
downloadmitmproxy-73e494770fe83b41f879d6f068f15c3056c943cf.tar.gz
mitmproxy-73e494770fe83b41f879d6f068f15c3056c943cf.tar.bz2
mitmproxy-73e494770fe83b41f879d6f068f15c3056c943cf.zip
web: add fetchApi convenience method
Diffstat (limited to 'web/src/js/utils.js')
-rw-r--r--web/src/js/utils.js18
1 files changed, 15 insertions, 3 deletions
diff --git a/web/src/js/utils.js b/web/src/js/utils.js
index 454bfe22..97737b20 100644
--- a/web/src/js/utils.js
+++ b/web/src/js/utils.js
@@ -76,11 +76,11 @@ export function reverseString(s) {
) + end;
}
-export function getCookie(name) {
+function getCookie(name) {
var r = document.cookie.match(new RegExp("\\b" + name + "=([^;]*)\\b"));
return r ? r[1] : undefined;
}
-var xsrf = $.param({_xsrf: getCookie("_xsrf")});
+const xsrf = `_xsrf=${getCookie("_xsrf")}`;
//Tornado XSRF Protection.
$.ajaxPrefilter(function (options) {
@@ -101,4 +101,16 @@ $(document).ajaxError(function (event, jqXHR, ajaxSettings, thrownError) {
console.error(thrownError, message, arguments);
actions.EventLogActions.add_event(thrownError + ": " + message);
alert(message);
-}); \ No newline at end of file
+});
+
+export function fetchApi(url, options) {
+ if(url.indexOf("?") === -1){
+ url += "?" + xsrf;
+ } else {
+ url += "&" + xsrf;
+ }
+ return fetch(url, {
+ ...options,
+ credentials: 'same-origin'
+ });
+} \ No newline at end of file