From e925015d10e554534b64f8b9fc16588a4c90fde1 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Sat, 12 Aug 2017 19:36:43 +0800 Subject: [web] Update fetch api to suite the static mode. --- web/src/js/flow/utils.js | 9 ++++++++- web/src/js/utils.js | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'web') diff --git a/web/src/js/flow/utils.js b/web/src/js/flow/utils.js index 3c38058e..9d4e1012 100644 --- a/web/src/js/flow/utils.js +++ b/web/src/js/flow/utils.js @@ -49,7 +49,14 @@ export var MessageUtils = { } else if (message === flow.response) { message = "response"; } - return `/flows/${flow.id}/${message}/content` + (view ? `/${view}` : ''); + 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}` : ''); + } } }; diff --git a/web/src/js/utils.js b/web/src/js/utils.js index e8470cec..68daa1ad 100644 --- a/web/src/js/utils.js +++ b/web/src/js/utils.js @@ -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", -- cgit v1.2.3 From 7d92cdf3bb349b8621d4f96cca87eb2b132b24b4 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Sat, 12 Aug 2017 19:38:52 +0800 Subject: [web] Hide ContentViewOptions in static mode --- web/src/js/components/FlowView/Messages.jsx | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'web') diff --git a/web/src/js/components/FlowView/Messages.jsx b/web/src/js/components/FlowView/Messages.jsx index 4a31faf4..b69dfb69 100644 --- a/web/src/js/components/FlowView/Messages.jsx +++ b/web/src/js/components/FlowView/Messages.jsx @@ -9,6 +9,7 @@ import ContentView from '../ContentView' import ContentViewOptions from '../ContentView/ContentViewOptions' import ValidateEditor from '../ValueEditor/ValidateEditor' import ValueEditor from '../ValueEditor/ValueEditor' +import HideInStatic from '../common/HideInStatic' import Headers from './Headers' import { startEdit, updateEdit } from '../../ducks/ui/flow' @@ -105,6 +106,7 @@ export class Request extends Component { onContentChange={content => updateFlow({ request: {content}})} message={flow.request}/> + {!noContent &&
uploadContent(flow, content, "request")}/>
} +
) } @@ -172,6 +175,7 @@ export class Response extends Component { message={flow.response} /> + {!noContent &&
} +
) } -- cgit v1.2.3 From cbdddefcc8f3ad19e50da5a31532c8abb0cb36f8 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Mon, 14 Aug 2017 10:11:48 +0800 Subject: [web] change the path name like `_flows` to `flows.json`. --- web/src/js/flow/utils.js | 4 ++-- web/src/js/utils.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'web') diff --git a/web/src/js/flow/utils.js b/web/src/js/flow/utils.js index 9d4e1012..cb37822a 100644 --- a/web/src/js/flow/utils.js +++ b/web/src/js/flow/utils.js @@ -51,8 +51,8 @@ export var MessageUtils = { } if (global.MITMWEB_STATIC) { let url = view ? - `/flows/${flow.id}/${message}/content/${view}` : - `/flows/${flow.id}/${message}/_content` + `/flows/${flow.id}/${message}/content/${view}.json` : + `/flows/${flow.id}/${message}/content.json` return url; } else { return `/flows/${flow.id}/${message}/content` + (view ? `/${view}` : ''); diff --git a/web/src/js/utils.js b/web/src/js/utils.js index 68daa1ad..505f74df 100644 --- a/web/src/js/utils.js +++ b/web/src/js/utils.js @@ -86,7 +86,7 @@ export function fetchApi(url, options={}) { if (global.MITMWEB_STATIC) { let path = url.split('/'), filename = path.pop() - filename = '_' + filename + filename += '.json' path.push(filename) let new_url = path.join('/') return _fetchApi(new_url, options) -- cgit v1.2.3 From 6560b0dcdba72085ce6c53d68a9e01d293936893 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Tue, 15 Aug 2017 22:21:08 +0800 Subject: [web] Change the api routing and minor fix. --- web/src/js/backends/static.js | 4 +--- web/src/js/flow/utils.js | 9 +-------- web/src/js/utils.js | 18 +++--------------- 3 files changed, 5 insertions(+), 26 deletions(-) (limited to 'web') diff --git a/web/src/js/backends/static.js b/web/src/js/backends/static.js index 6657fecf..7e87a5ed 100644 --- a/web/src/js/backends/static.js +++ b/web/src/js/backends/static.js @@ -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) { diff --git a/web/src/js/flow/utils.js b/web/src/js/flow/utils.js index cb37822a..9915a639 100644 --- a/web/src/js/flow/utils.js +++ b/web/src/js/flow/utils.js @@ -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'); } }; diff --git a/web/src/js/utils.js b/web/src/js/utils.js index 505f74df..3aeba1b1 100644 --- a/web/src/js/utils.js +++ b/web/src/js/utils.js @@ -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", -- cgit v1.2.3 From 3f497640ab0a69838fb605ed9a4b1cee76e462aa Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Tue, 15 Aug 2017 22:23:21 +0800 Subject: [web] Update tests. --- .../ContentView/__snapshots__/ContentViewOptionsSpec.js.snap | 2 +- .../components/ContentView/__snapshots__/ContentViewSpec.js.snap | 2 +- .../ContentView/__snapshots__/DownloadContentButtonSpec.js.snap | 2 +- .../components/ContentView/__snapshots__/MetaViewsSpec.js.snap | 2 +- .../components/FlowView/__snapshots__/MessagesSpec.js.snap | 4 ++-- .../js/__tests__/components/__snapshots__/ContentViewSpec.js.snap | 2 +- web/src/js/__tests__/flow/utilsSpec.js | 6 +++--- 7 files changed, 10 insertions(+), 10 deletions(-) (limited to 'web') diff --git a/web/src/js/__tests__/components/ContentView/__snapshots__/ContentViewOptionsSpec.js.snap b/web/src/js/__tests__/components/ContentView/__snapshots__/ContentViewOptionsSpec.js.snap index e3561ec1..01fab0a7 100644 --- a/web/src/js/__tests__/components/ContentView/__snapshots__/ContentViewOptionsSpec.js.snap +++ b/web/src/js/__tests__/components/ContentView/__snapshots__/ContentViewOptionsSpec.js.snap @@ -13,7 +13,7 @@ exports[`ContentViewOptions Component should render correctly 1`] = `   `; diff --git a/web/src/js/__tests__/components/ContentView/__snapshots__/DownloadContentButtonSpec.js.snap b/web/src/js/__tests__/components/ContentView/__snapshots__/DownloadContentButtonSpec.js.snap index 66900ca4..4c578a0c 100644 --- a/web/src/js/__tests__/components/ContentView/__snapshots__/DownloadContentButtonSpec.js.snap +++ b/web/src/js/__tests__/components/ContentView/__snapshots__/DownloadContentButtonSpec.js.snap @@ -3,7 +3,7 @@ exports[`DownloadContentButton Component should render correctly 1`] = ` { let msg = "foo", view = "bar", flow = { request: msg, id: 1} expect(utils.MessageUtils.getContentURL(flow, msg, view)).toEqual( - "/flows/1/request/content/bar" + "/flows/1/request/content/bar.json" ) expect(utils.MessageUtils.getContentURL(flow, msg, '')).toEqual( - "/flows/1/request/content" + "/flows/1/request/_content" ) // response flow = {response: msg, id: 2} expect(utils.MessageUtils.getContentURL(flow, msg, view)).toEqual( - "/flows/2/response/content/bar" + "/flows/2/response/content/bar.json" ) }) }) -- cgit v1.2.3