[web] Change the api routing and minor fix.

This commit is contained in:
Matthew Shao 2017-08-15 22:21:08 +08:00
parent cbdddefcc8
commit 6560b0dcdb
5 changed files with 13 additions and 34 deletions

View File

@ -466,10 +466,10 @@ class Application(tornado.web.Application):
self.master = master
handlers = [
(r"/", IndexHandler),
(r"/filter-help", FilterHelp),
(r"/filter-help(?:\.json)?", FilterHelp),
(r"/updates", ClientConnection),
(r"/events", Events),
(r"/flows", Flows),
(r"/events(?:\.json)?", Events),
(r"/flows(?:\.json)?", Flows),
(r"/flows/dump", DumpFlows),
(r"/flows/resume", ResumeFlows),
(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\-]+)/replay", ReplayFlow),
(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),
(r"/settings", Settings),
(r"/settings(?:\.json)?", Settings),
(r"/clear", ClearAll),
(r"/options", Options),
(r"/options(?:\.json)?", Options),
(r"/options/save", SaveOptions)
]
settings = dict(

View File

@ -54,7 +54,7 @@ class StaticViewer:
path = os.path.join(self.path, 'flows', f.id, m)
if not os.path.exists(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_view

View File

@ -11,10 +11,8 @@ export default class StaticBackend {
}
onOpen() {
this.fetchData("settings")
this.fetchData("flows")
this.fetchData("events")
this.fetchData("options")
// this.fetchData("events") # TODO: Add events log to static viewer.
}
fetchData(resource) {

View File

@ -49,14 +49,7 @@ export var MessageUtils = {
} else if (message === flow.response) {
message = "response";
}
if (global.MITMWEB_STATIC) {
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}` : '');
}
return `/flows/${flow.id}/${message}/` + (view ? `content/${view}.json` : '_content');
}
};

View File

@ -81,27 +81,15 @@ 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 += '.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 (url.indexOf("?") === -1) {
url += "?" + xsrf;
} else {
url += "&" + xsrf;
}
} else {
url += '.json'
}
return fetch(url, {
@ -110,7 +98,7 @@ function _fetchApi(url, options={}) {
});
}
fetchApi.put = (url, json, options) => _fetchApi(
fetchApi.put = (url, json, options) => fetchApi(
url,
{
method: "PUT",