web addon: add connection info

addon-dailer
lqqyt2423 2 years ago
parent 217ac902ed
commit 7d0566ccc3

@ -16,7 +16,6 @@ import { ConnectionManager, IConnection } from './lib/connection'
interface IState { interface IState {
flows: Flow[] flows: Flow[]
flow: Flow | null flow: Flow | null
flowTab: 'Headers' | 'Preview' | 'Response'
wsStatus: 'open' | 'close' | 'connecting' wsStatus: 'open' | 'close' | 'connecting'
} }
@ -43,7 +42,6 @@ class App extends React.Component<IProps, IState> {
this.state = { this.state = {
flows: this.flowMgr.showList(), flows: this.flowMgr.showList(),
flow: null, flow: null,
flowTab: 'Headers', // Headers, Preview, Response
wsStatus: 'close', wsStatus: 'close',
} }
@ -110,9 +108,10 @@ class App extends React.Component<IProps, IState> {
// console.log('msg:', msg) // console.log('msg:', msg)
if (msg.type === MessageType.CONN) { if (msg.type === MessageType.CONN) {
this.connMgr.set(msg.id, msg.content as IConnection) this.connMgr.add(msg.id, msg.content as IConnection)
this.setState({ flows: this.state.flows })
} else if (msg.type === MessageType.REQUEST) { } else if (msg.type === MessageType.REQUEST) {
const flow = new Flow(msg) const flow = new Flow(msg, this.connMgr)
this.flowMgr.add(flow) this.flowMgr.add(flow)
let shouldScroll = false let shouldScroll = false

@ -91,7 +91,26 @@ class ViewFlow extends React.Component<Iprops, IState> {
const { flow } = this.props const { flow } = this.props
if (!flow) return null if (!flow) return null
return <div>detail todo</div> const conn = flow.getConn()
if (!conn) return null
return (
<div>
<div className="header-block">
<p>Server Connection</p>
<div className="header-block-content">
<p>Address: {conn.serverConn.address}</p>
<p>Resolved Address: {conn.serverConn.peername}</p>
</div>
</div>
<div className="header-block">
<p>Client Connection</p>
<div className="header-block-content">
<p>Address: {conn.clientConn.address}</p>
</div>
</div>
</div>
)
} }
render() { render() {

@ -1,5 +1,4 @@
export interface IConnection { export interface IConnection {
id: string
clientConn: { clientConn: {
id: string id: string
tls: boolean tls: boolean
@ -23,7 +22,7 @@ export class ConnectionManager {
return this._map.get(id) return this._map.get(id)
} }
set(id: string, conn: IConnection) { add(id: string, conn: IConnection) {
this._map.set(id, conn) this._map.set(id, conn)
} }

@ -1,3 +1,4 @@
import type { ConnectionManager, IConnection } from './connection'
import { IMessage, MessageType } from './message' import { IMessage, MessageType } from './message'
import { arrayBufferToBase64, bufHexView, getSize, isTextBody } from './utils' import { arrayBufferToBase64, bufHexView, getSize, isTextBody } from './utils'
@ -73,7 +74,10 @@ export class Flow {
private _previewRequestBody: IPreviewBody | null = null private _previewRequestBody: IPreviewBody | null = null
private _hexviewResponseBody: string | null = null private _hexviewResponseBody: string | null = null
constructor(msg: IMessage) { private connMgr: ConnectionManager;
private conn: IConnection | undefined;
constructor(msg: IMessage, connMgr: ConnectionManager) {
this.no = ++Flow.curNo this.no = ++Flow.curNo
this.id = msg.id this.id = msg.id
this.waitIntercept = msg.waitIntercept this.waitIntercept = msg.waitIntercept
@ -89,6 +93,8 @@ export class Flow {
this._isTextResponse = null this._isTextResponse = null
this._requestBody = null this._requestBody = null
this._responseBody = null this._responseBody = null
this.connMgr = connMgr
} }
public addRequestBody(msg: IMessage): Flow { public addRequestBody(msg: IMessage): Flow {
@ -248,6 +254,12 @@ export class Flow {
this._hexviewResponseBody = bufHexView(this.response.body) this._hexviewResponseBody = bufHexView(this.response.body)
return this._hexviewResponseBody return this._hexviewResponseBody
} }
public getConn(): IConnection | undefined {
if (this.conn) return this.conn
this.conn = this.connMgr.get(this.connId)
return this.conn
}
} }
export class FlowManager { export class FlowManager {

Loading…
Cancel
Save