Skip to content

Commit

Permalink
add intercept flag to connection
Browse files Browse the repository at this point in the history
  • Loading branch information
lqqyt2423 committed Feb 13, 2023
1 parent e21274c commit 62ce93d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
3 changes: 2 additions & 1 deletion proxy/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion web/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class App extends React.Component<IProps, IState> {

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 })
}
Expand Down
25 changes: 17 additions & 8 deletions web/client/src/components/ViewFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,18 @@ class ViewFlow extends React.Component<Iprops, IState> {
{
!conn ? null :
<>
<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>
{
!conn.serverConn ? null :
<>
<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">
Expand All @@ -121,7 +126,11 @@ class ViewFlow extends React.Component<Iprops, IState> {
<p>Connection Info</p>
<div className="header-block-content">
<p>Id: {conn.clientConn.id}</p>
<p>Opening: {conn.opening ? 'true' : 'false'}</p>
<p>Intercept: {conn.intercept ? 'true' : 'false'}</p>
{
conn.opening == null ? null :
<p>Opening: {conn.opening ? 'true' : 'false'}</p>
}
{
conn.flowCount == null ? null :
<p>Flow Count: {conn.flowCount}</p>
Expand Down
5 changes: 3 additions & 2 deletions web/client/src/lib/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 62ce93d

Please sign in to comment.