aboutsummaryrefslogtreecommitdiffstats
path: root/web/src
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
parent89fc438e324c359df8b387a39c9e8beab1df54d0 (diff)
downloadmitmproxy-73e494770fe83b41f879d6f068f15c3056c943cf.tar.gz
mitmproxy-73e494770fe83b41f879d6f068f15c3056c943cf.tar.bz2
mitmproxy-73e494770fe83b41f879d6f068f15c3056c943cf.zip
web: add fetchApi convenience method
Diffstat (limited to 'web/src')
-rw-r--r--web/src/js/actions.js7
-rw-r--r--web/src/js/utils.js18
2 files changed, 17 insertions, 8 deletions
diff --git a/web/src/js/actions.js b/web/src/js/actions.js
index 5c6f0167..9325765b 100644
--- a/web/src/js/actions.js
+++ b/web/src/js/actions.js
@@ -1,7 +1,6 @@
import $ from "jquery";
-import _ from "lodash";
import {AppDispatcher} from "./dispatcher.js";
-import {getCookie} from "./utils.js";
+import {fetchApi} from "./utils.js";
export var ActionTypes = {
// Connection
@@ -122,12 +121,10 @@ export var FlowActions = {
download: () => window.location = "/flows/dump",
upload: (file) => {
- var xsrf = $.param({_xsrf: getCookie("_xsrf")});
- //console.log(xsrf);
var filereader = new FileReader();
filereader.file = file;
filereader.onload = (e) => {
- fetch("/flows/dump?"+xsrf, {
+ fetchApi("/flows/dump", {
method: 'post',
body: e.currentTarget.result
})
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