From 62ce93db7dfb7bf41129515f48145a5c4e3f8523 Mon Sep 17 00:00:00 2001 From: lqqyt2423 <974923609@qq.com> Date: Mon, 13 Feb 2023 16:07:46 +0800 Subject: [PATCH] add intercept flag to connection --- proxy/connection.go | 3 ++- proxy/proxy.go | 4 +++- web/client/src/App.tsx | 2 +- web/client/src/components/ViewFlow.tsx | 25 +++++++++++++++++-------- web/client/src/lib/connection.ts | 5 +++-- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/proxy/connection.go b/proxy/connection.go index 8262dd5..e8e8ce1 100644 --- a/proxy/connection.go +++ b/proxy/connection.go @@ -80,7 +80,8 @@ var connContextKey = new(struct{}) type ConnContext struct { ClientConn *ClientConn `json:"clientConn"` ServerConn *ServerConn `json:"serverConn"` - FlowCount uint32 `json:"-"` + Intercept bool `json:"intercept"` // Indicates whether to parse HTTPS + FlowCount uint32 `json:"-"` // Number of HTTP requests made on the same connection proxy *Proxy pipeConn *pipeConn diff --git a/proxy/proxy.go b/proxy/proxy.go index d4cfdf0..f935233 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -285,9 +285,11 @@ func (proxy *Proxy) handleConnect(res http.ResponseWriter, req *http.Request) { "host": req.Host, }) + shouldIntercept := proxy.shouldIntercept == nil || proxy.shouldIntercept(req.Host) f := newFlow() f.Request = newRequest(req) f.ConnContext = req.Context().Value(connContextKey).(*ConnContext) + f.ConnContext.Intercept = shouldIntercept defer f.finish() // trigger addon event Requestheaders @@ -297,7 +299,7 @@ func (proxy *Proxy) handleConnect(res http.ResponseWriter, req *http.Request) { var conn net.Conn var err error - if proxy.shouldIntercept == nil || proxy.shouldIntercept(req.Host) { + if shouldIntercept { log.Debugf("begin intercept %v", req.Host) conn, err = proxy.interceptor.dial(req) } else { diff --git a/web/client/src/App.tsx b/web/client/src/App.tsx index 19fce97..a111463 100644 --- a/web/client/src/App.tsx +++ b/web/client/src/App.tsx @@ -111,7 +111,7 @@ class App extends React.Component { if (msg.type === MessageType.CONN) { const conn = msg.content as IConnection - conn.opening = true + if (conn.intercept) conn.opening = true this.connMgr.add(msg.id, conn) this.setState({ flows: this.state.flows }) } diff --git a/web/client/src/components/ViewFlow.tsx b/web/client/src/components/ViewFlow.tsx index edd3700..c118f61 100644 --- a/web/client/src/components/ViewFlow.tsx +++ b/web/client/src/components/ViewFlow.tsx @@ -104,13 +104,18 @@ class ViewFlow extends React.Component { { !conn ? null : <> -
-

Server Connection

-
-

Address: {conn.serverConn.address}

-

Resolved Address: {conn.serverConn.peername}

-
-
+ { + !conn.serverConn ? null : + <> +
+

Server Connection

+
+

Address: {conn.serverConn.address}

+

Resolved Address: {conn.serverConn.peername}

+
+
+ + }

Client Connection

@@ -121,7 +126,11 @@ class ViewFlow extends React.Component {

Connection Info

Id: {conn.clientConn.id}

-

Opening: {conn.opening ? 'true' : 'false'}

+

Intercept: {conn.intercept ? 'true' : 'false'}

+ { + conn.opening == null ? null : +

Opening: {conn.opening ? 'true' : 'false'}

+ } { conn.flowCount == null ? null :

Flow Count: {conn.flowCount}

diff --git a/web/client/src/lib/connection.ts b/web/client/src/lib/connection.ts index fac80b9..e3e07dc 100644 --- a/web/client/src/lib/connection.ts +++ b/web/client/src/lib/connection.ts @@ -4,12 +4,13 @@ export interface IConnection { tls: boolean address: string } - serverConn: { + serverConn?: { id: string address: string peername: string } - opening: boolean + intercept: boolean + opening?: boolean flowCount?: number }