diff options
author | Jason <jason.daurus@gmail.com> | 2016-06-17 21:54:31 +0800 |
---|---|---|
committer | Jason <jason.daurus@gmail.com> | 2016-06-17 21:54:31 +0800 |
commit | e4addd60f1ffbb445a8c05f3fb2b6c6e61bd7b93 (patch) | |
tree | cb5e3be10e8bb813c1ade3aa88204460317d2548 /web/src/js/components/FlowView.jsx | |
parent | 16a28eca258e07d45c7e2a8ee95368d4eb077d4d (diff) | |
parent | 9c6199db9be34fad18eaedb86463333671ae190a (diff) | |
download | mitmproxy-e4addd60f1ffbb445a8c05f3fb2b6c6e61bd7b93.tar.gz mitmproxy-e4addd60f1ffbb445a8c05f3fb2b6c6e61bd7b93.tar.bz2 mitmproxy-e4addd60f1ffbb445a8c05f3fb2b6c6e61bd7b93.zip |
Merge branch 'master' into websocket
Conflicts:
mitmproxy/web/static/app.css
mitmproxy/web/static/app.js
web/src/js/components/ProxyApp.jsx
Diffstat (limited to 'web/src/js/components/FlowView.jsx')
-rw-r--r-- | web/src/js/components/FlowView.jsx | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/web/src/js/components/FlowView.jsx b/web/src/js/components/FlowView.jsx new file mode 100644 index 00000000..23f8b3ea --- /dev/null +++ b/web/src/js/components/FlowView.jsx @@ -0,0 +1,107 @@ +import React, { Component } from 'react' +import _ from 'lodash' + +import Nav from './FlowView/Nav' +import { Request, Response, Error } from './FlowView/Messages' +import Details from './FlowView/Details' +import Prompt from './Prompt' + +export default class FlowView extends Component { + + static allTabs = { Request, Response, Error, Details } + + constructor(props, context) { + super(props, context) + + this.state = { prompt: false } + + this.closePrompt = this.closePrompt.bind(this) + this.selectTab = this.selectTab.bind(this) + } + + getTabs() { + return ['request', 'response', 'error'].filter(k => this.props.flow[k]).concat(['details']) + } + + nextTab(increment) { + const tabs = this.getTabs() + // JS modulo operator doesn't correct negative numbers, make sure that we are positive. + this.selectTab(tabs[(tabs.indexOf(this.props.tab) + increment + tabs.length) % tabs.length]) + } + + selectTab(panel) { + this.props.updateLocation(`/flows/${this.props.flow.id}/${panel}`) + } + + closePrompt(edit) { + this.setState({ prompt: false }) + if (edit) { + this.refs.tab.edit(edit) + } + } + + promptEdit() { + let options + + switch (this.props.tab) { + + case 'request': + options = [ + 'method', + 'url', + { text: 'http version', key: 'v' }, + 'header' + ] + break + + case 'response': + options = [ + { text: 'http version', key: 'v' }, + 'code', + 'message', + 'header' + ] + break + + case 'details': + return + + default: + throw 'Unknown tab for edit: ' + this.props.tab + } + + this.setState({ prompt: { options, done: this.closePrompt } }) + } + + render() { + const tabs = this.getTabs() + let { flow, tab: active } = this.props + + if (tabs.indexOf(active) < 0) { + if (active === 'response' && flow.error) { + active = 'error' + } else if (active === 'error' && flow.response) { + active = 'response' + } else { + active = tabs[0] + } + } + + const Tab = FlowView.allTabs[_.capitalize(active)] + + return ( + <div className="flow-detail" onScroll={this.adjustHead}> + <Nav + flow={flow} + tabs={tabs} + active={active} + onSelectTab={this.selectTab} + /> + <Tab ref="tab" flow={flow}/> + {this.state.prompt && ( + <Prompt {...this.state.prompt}/> + )} + </div> + ) + } +} |