mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-29 11:03:13 +00:00
[web] Change the api routing and minor fix.
This commit is contained in:
parent
cbdddefcc8
commit
6560b0dcdb
@ -466,10 +466,10 @@ class Application(tornado.web.Application):
|
|||||||
self.master = master
|
self.master = master
|
||||||
handlers = [
|
handlers = [
|
||||||
(r"/", IndexHandler),
|
(r"/", IndexHandler),
|
||||||
(r"/filter-help", FilterHelp),
|
(r"/filter-help(?:\.json)?", FilterHelp),
|
||||||
(r"/updates", ClientConnection),
|
(r"/updates", ClientConnection),
|
||||||
(r"/events", Events),
|
(r"/events(?:\.json)?", Events),
|
||||||
(r"/flows", Flows),
|
(r"/flows(?:\.json)?", Flows),
|
||||||
(r"/flows/dump", DumpFlows),
|
(r"/flows/dump", DumpFlows),
|
||||||
(r"/flows/resume", ResumeFlows),
|
(r"/flows/resume", ResumeFlows),
|
||||||
(r"/flows/kill", KillFlows),
|
(r"/flows/kill", KillFlows),
|
||||||
@ -479,13 +479,13 @@ class Application(tornado.web.Application):
|
|||||||
(r"/flows/(?P<flow_id>[0-9a-f\-]+)/duplicate", DuplicateFlow),
|
(r"/flows/(?P<flow_id>[0-9a-f\-]+)/duplicate", DuplicateFlow),
|
||||||
(r"/flows/(?P<flow_id>[0-9a-f\-]+)/replay", ReplayFlow),
|
(r"/flows/(?P<flow_id>[0-9a-f\-]+)/replay", ReplayFlow),
|
||||||
(r"/flows/(?P<flow_id>[0-9a-f\-]+)/revert", RevertFlow),
|
(r"/flows/(?P<flow_id>[0-9a-f\-]+)/revert", RevertFlow),
|
||||||
(r"/flows/(?P<flow_id>[0-9a-f\-]+)/(?P<message>request|response)/content", FlowContent),
|
(r"/flows/(?P<flow_id>[0-9a-f\-]+)/(?P<message>request|response)/_content", FlowContent),
|
||||||
(
|
(
|
||||||
r"/flows/(?P<flow_id>[0-9a-f\-]+)/(?P<message>request|response)/content/(?P<content_view>[0-9a-zA-Z\-\_]+)",
|
r"/flows/(?P<flow_id>[0-9a-f\-]+)/(?P<message>request|response)/content/(?P<content_view>[0-9a-zA-Z\-\_]+)(?:\.json)?",
|
||||||
FlowContentView),
|
FlowContentView),
|
||||||
(r"/settings", Settings),
|
(r"/settings(?:\.json)?", Settings),
|
||||||
(r"/clear", ClearAll),
|
(r"/clear", ClearAll),
|
||||||
(r"/options", Options),
|
(r"/options(?:\.json)?", Options),
|
||||||
(r"/options/save", SaveOptions)
|
(r"/options/save", SaveOptions)
|
||||||
]
|
]
|
||||||
settings = dict(
|
settings = dict(
|
||||||
|
@ -54,7 +54,7 @@ class StaticViewer:
|
|||||||
path = os.path.join(self.path, 'flows', f.id, m)
|
path = os.path.join(self.path, 'flows', f.id, m)
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
with open(os.path.join(path, 'content.json'), 'wb') as content_file:
|
with open(os.path.join(path, '_content'), 'wb') as content_file:
|
||||||
content_file.write(message.raw_content)
|
content_file.write(message.raw_content)
|
||||||
|
|
||||||
# content_view
|
# content_view
|
||||||
|
@ -11,10 +11,8 @@ export default class StaticBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onOpen() {
|
onOpen() {
|
||||||
this.fetchData("settings")
|
|
||||||
this.fetchData("flows")
|
this.fetchData("flows")
|
||||||
this.fetchData("events")
|
// this.fetchData("events") # TODO: Add events log to static viewer.
|
||||||
this.fetchData("options")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchData(resource) {
|
fetchData(resource) {
|
||||||
|
@ -49,14 +49,7 @@ export var MessageUtils = {
|
|||||||
} else if (message === flow.response) {
|
} else if (message === flow.response) {
|
||||||
message = "response";
|
message = "response";
|
||||||
}
|
}
|
||||||
if (global.MITMWEB_STATIC) {
|
return `/flows/${flow.id}/${message}/` + (view ? `content/${view}.json` : '_content');
|
||||||
let url = view ?
|
|
||||||
`/flows/${flow.id}/${message}/content/${view}.json` :
|
|
||||||
`/flows/${flow.id}/${message}/content.json`
|
|
||||||
return url;
|
|
||||||
} else {
|
|
||||||
return `/flows/${flow.id}/${message}/content` + (view ? `/${view}` : '');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -81,27 +81,15 @@ function getCookie(name) {
|
|||||||
}
|
}
|
||||||
const xsrf = `_xsrf=${getCookie("_xsrf")}`;
|
const xsrf = `_xsrf=${getCookie("_xsrf")}`;
|
||||||
|
|
||||||
|
|
||||||
export function fetchApi(url, options={}) {
|
export function fetchApi(url, options={}) {
|
||||||
if (global.MITMWEB_STATIC) {
|
|
||||||
let path = url.split('/'),
|
|
||||||
filename = path.pop()
|
|
||||||
filename += '.json'
|
|
||||||
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 (options.method && options.method !== "GET") {
|
||||||
if (url.indexOf("?") === -1) {
|
if (url.indexOf("?") === -1) {
|
||||||
url += "?" + xsrf;
|
url += "?" + xsrf;
|
||||||
} else {
|
} else {
|
||||||
url += "&" + xsrf;
|
url += "&" + xsrf;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
url += '.json'
|
||||||
}
|
}
|
||||||
|
|
||||||
return fetch(url, {
|
return fetch(url, {
|
||||||
@ -110,7 +98,7 @@ function _fetchApi(url, options={}) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchApi.put = (url, json, options) => _fetchApi(
|
fetchApi.put = (url, json, options) => fetchApi(
|
||||||
url,
|
url,
|
||||||
{
|
{
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
|
Loading…
Reference in New Issue
Block a user