From 367106c8006b1fce068da9e2fccbf68b0517cc82 Mon Sep 17 00:00:00 2001 From: liqiang <974923609@qq.com> Date: Wed, 24 Mar 2021 19:16:54 +0800 Subject: [PATCH] fix: breakPointRules --- addon/web/client/src/App.js | 1 + addon/web/client/src/message.js | 9 +++++---- addon/web/conn.go | 29 ++++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/addon/web/client/src/App.js b/addon/web/client/src/App.js index 3b7eb01..de96f04 100644 --- a/addon/web/client/src/App.js +++ b/addon/web/client/src/App.js @@ -66,6 +66,7 @@ class App extends React.Component { else if (msg.type === 'requestBody') { const flow = this.flowMgr.get(msg.id) if (!flow) return + flow.waitIntercept = msg.waitIntercept flow.request.body = msg.content this.setState({ flows: this.state.flows }) } diff --git a/addon/web/client/src/message.js b/addon/web/client/src/message.js index 10c2e2f..6205b5c 100644 --- a/addon/web/client/src/message.js +++ b/addon/web/client/src/message.js @@ -69,19 +69,20 @@ export const buildMessageEdit = (messageType, flow) => { throw new Error('invalid message type') } + const bodyLen = (body && body.byteLength) ? body.byteLength : 0 const headerBytes = new TextEncoder().encode(JSON.stringify(header)) - const len = 2 + 36 + 4 + headerBytes.byteLength + 4 + body.byteLength + const len = 2 + 36 + 4 + headerBytes.byteLength + 4 + bodyLen const data = new ArrayBuffer(len) const view = new Uint8Array(data) view[0] = 1 view[1] = messageType - view.set(new TextEncoder().encode(flow.id), 3) + view.set(new TextEncoder().encode(flow.id), 2) view.set(headerBytes, 2 + 36 + 4) - view.set(body, 2 + 36 + 4 + headerBytes.byteLength + 4) + if (bodyLen) view.set(body, 2 + 36 + 4 + headerBytes.byteLength + 4) const view2 = new DataView(data) view2.setUint32(2 + 36, headerBytes.byteLength) - view2.setUint32(2 + 36 + 4 + headerBytes.byteLength, body.byteLength) + view2.setUint32(2 + 36 + 4 + headerBytes.byteLength, bodyLen) return view } diff --git a/addon/web/conn.go b/addon/web/conn.go index 07fbaf4..946d3d2 100644 --- a/addon/web/conn.go +++ b/addon/web/conn.go @@ -1,6 +1,7 @@ package web import ( + "strings" "sync" "github.com/gorilla/websocket" @@ -94,10 +95,36 @@ func (c *concurrentConn) initWaitChan(key string) chan interface{} { // 是否拦截 func (c *concurrentConn) isIntercpt(f *flow.Flow, after *messageFlow) bool { - if after.mType != messageTypeRequest { + if after.mType != messageTypeRequestBody && after.mType != messageTypeResponseBody { return false } + if len(c.breakPointRules) == 0 { + return false + } + + var action int + if after.mType == messageTypeRequestBody { + action = 1 + } else { + action = 2 + } + + for _, rule := range c.breakPointRules { + if rule.URL == "" { + continue + } + if action&rule.Action == 0 { + continue + } + if rule.Method != "" && rule.Method != f.Request.Method { + continue + } + if strings.Contains(f.Request.URL.String(), rule.URL) { + return true + } + } + return false }