|
|
@ -8,12 +8,12 @@ import BreakPoint from './components/BreakPoint'
|
|
|
|
import EditFlow from './components/EditFlow'
|
|
|
|
import EditFlow from './components/EditFlow'
|
|
|
|
|
|
|
|
|
|
|
|
import { FlowManager } from './flow'
|
|
|
|
import { FlowManager } from './flow'
|
|
|
|
import { isTextBody, getSize } from './utils'
|
|
|
|
import { isTextBody } from './utils'
|
|
|
|
import { parseMessage, SendMessageType, buildMessageMeta, IFlow, MessageType, IRequest, IResponse } from './message'
|
|
|
|
import { parseMessage, SendMessageType, buildMessageMeta, Flow, MessageType, IResponse } from './message'
|
|
|
|
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
interface IState {
|
|
|
|
flows: IFlow[]
|
|
|
|
flows: Flow[]
|
|
|
|
flow: IFlow | null
|
|
|
|
flow: Flow | null
|
|
|
|
flowTab: 'Headers' | 'Preview' | 'Response'
|
|
|
|
flowTab: 'Headers' | 'Preview' | 'Response'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -68,29 +68,26 @@ class App extends React.Component<any, IState> {
|
|
|
|
// console.log('msg:', msg)
|
|
|
|
// console.log('msg:', msg)
|
|
|
|
|
|
|
|
|
|
|
|
if (msg.type === MessageType.REQUEST) {
|
|
|
|
if (msg.type === MessageType.REQUEST) {
|
|
|
|
const flow = { id: msg.id, request: msg.content as IRequest, waitIntercept: msg.waitIntercept }
|
|
|
|
const flow = new Flow(msg)
|
|
|
|
this.flowMgr.add(flow)
|
|
|
|
this.flowMgr.add(flow)
|
|
|
|
this.setState({ flows: this.flowMgr.showList() })
|
|
|
|
this.setState({ flows: this.flowMgr.showList() })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (msg.type === MessageType.REQUEST_BODY) {
|
|
|
|
else if (msg.type === MessageType.REQUEST_BODY) {
|
|
|
|
const flow = this.flowMgr.get(msg.id)
|
|
|
|
const flow = this.flowMgr.get(msg.id)
|
|
|
|
if (!flow) return
|
|
|
|
if (!flow) return
|
|
|
|
flow.waitIntercept = msg.waitIntercept
|
|
|
|
flow.addRequestBody(msg)
|
|
|
|
flow.request.body = msg.content as ArrayBuffer
|
|
|
|
|
|
|
|
this.setState({ flows: this.state.flows })
|
|
|
|
this.setState({ flows: this.state.flows })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (msg.type === MessageType.RESPONSE) {
|
|
|
|
else if (msg.type === MessageType.RESPONSE) {
|
|
|
|
const flow = this.flowMgr.get(msg.id)
|
|
|
|
const flow = this.flowMgr.get(msg.id)
|
|
|
|
if (!flow) return
|
|
|
|
if (!flow) return
|
|
|
|
flow.waitIntercept = msg.waitIntercept
|
|
|
|
flow.addResponse(msg)
|
|
|
|
flow.response = msg.content as IResponse
|
|
|
|
|
|
|
|
this.setState({ flows: this.state.flows })
|
|
|
|
this.setState({ flows: this.state.flows })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (msg.type === MessageType.RESPONSE_BODY) {
|
|
|
|
else if (msg.type === MessageType.RESPONSE_BODY) {
|
|
|
|
const flow = this.flowMgr.get(msg.id)
|
|
|
|
const flow = this.flowMgr.get(msg.id)
|
|
|
|
if (!flow || !flow.response) return
|
|
|
|
if (!flow || !flow.response) return
|
|
|
|
flow.waitIntercept = msg.waitIntercept
|
|
|
|
flow.addResponseBody(msg)
|
|
|
|
flow.response.body = msg.content as ArrayBuffer
|
|
|
|
|
|
|
|
this.setState({ flows: this.state.flows })
|
|
|
|
this.setState({ flows: this.state.flows })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -257,32 +254,24 @@ class App extends React.Component<any, IState> {
|
|
|
|
<tbody>
|
|
|
|
<tbody>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
flows.map(f => {
|
|
|
|
flows.map(f => {
|
|
|
|
const url = f.request.url
|
|
|
|
const fp = f.preview()
|
|
|
|
const u = new URL(url)
|
|
|
|
|
|
|
|
let host = u.host
|
|
|
|
|
|
|
|
if (host.length > 35) host = host.slice(0, 35) + '...'
|
|
|
|
|
|
|
|
let path = u.pathname + u.search
|
|
|
|
|
|
|
|
if (path.length > 65) path = path.slice(0, 65) + '...'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const request = f.request
|
|
|
|
|
|
|
|
const response: IResponse = (f.response || {}) as any
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const classNames = []
|
|
|
|
const classNames = []
|
|
|
|
if (this.state.flow && this.state.flow.id === f.id) classNames.push('tr-selected')
|
|
|
|
if (this.state.flow && this.state.flow.id === fp.id) classNames.push('tr-selected')
|
|
|
|
if (f.waitIntercept) classNames.push('tr-wait-intercept')
|
|
|
|
if (fp.waitIntercept) classNames.push('tr-wait-intercept')
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<tr className={classNames.length ? classNames.join(' ') : undefined} key={f.id}
|
|
|
|
<tr className={classNames.length ? classNames.join(' ') : undefined} key={fp.id}
|
|
|
|
onClick={() => {
|
|
|
|
onClick={() => {
|
|
|
|
this.setState({ flow: f })
|
|
|
|
this.setState({ flow: f })
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
>
|
|
|
|
<td>{f.no}</td>
|
|
|
|
<td>{fp.no}</td>
|
|
|
|
<td>{host}</td>
|
|
|
|
<td>{fp.host}</td>
|
|
|
|
<td>{path}</td>
|
|
|
|
<td>{fp.path}</td>
|
|
|
|
<td>{request.method}</td>
|
|
|
|
<td>{fp.method}</td>
|
|
|
|
<td>{response.statusCode || '(pending)'}</td>
|
|
|
|
<td>{fp.statusCode}</td>
|
|
|
|
<td>{getSize(response)}</td>
|
|
|
|
<td>{fp.size}</td>
|
|
|
|
</tr>
|
|
|
|
</tr>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|