mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 15:37:45 +00:00
[web] Update fetch api to suite the static mode.
This commit is contained in:
parent
1b129b5099
commit
e925015d10
@ -49,8 +49,15 @@ export var MessageUtils = {
|
||||
} else if (message === flow.response) {
|
||||
message = "response";
|
||||
}
|
||||
if (global.MITMWEB_STATIC) {
|
||||
let url = view ?
|
||||
`/flows/${flow.id}/${message}/content/${view}` :
|
||||
`/flows/${flow.id}/${message}/_content`
|
||||
return url;
|
||||
} else {
|
||||
return `/flows/${flow.id}/${message}/content` + (view ? `/${view}` : '');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export var RequestUtils = _.extend(MessageUtils, {
|
||||
|
@ -81,7 +81,21 @@ function getCookie(name) {
|
||||
}
|
||||
const xsrf = `_xsrf=${getCookie("_xsrf")}`;
|
||||
|
||||
|
||||
export function fetchApi(url, options={}) {
|
||||
if (global.MITMWEB_STATIC) {
|
||||
let path = url.split('/'),
|
||||
filename = path.pop()
|
||||
filename = '_' + filename
|
||||
path.push(filename)
|
||||
let new_url = path.join('/')
|
||||
return _fetchApi(new_url, options)
|
||||
} else {
|
||||
return _fetchApi(url, options)
|
||||
}
|
||||
}
|
||||
|
||||
function _fetchApi(url, options={}) {
|
||||
if (options.method && options.method !== "GET") {
|
||||
if (url.indexOf("?") === -1) {
|
||||
url += "?" + xsrf;
|
||||
@ -96,7 +110,7 @@ export function fetchApi(url, options={}) {
|
||||
});
|
||||
}
|
||||
|
||||
fetchApi.put = (url, json, options) => fetchApi(
|
||||
fetchApi.put = (url, json, options) => _fetchApi(
|
||||
url,
|
||||
{
|
||||
method: "PUT",
|
||||
|
Loading…
Reference in New Issue
Block a user