fix: breakPointRules

addon-dailer
liqiang 4 years ago
parent 797780d169
commit 367106c800

@ -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 })
}

@ -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
}

@ -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
}

Loading…
Cancel
Save