diff --git a/addon/web/client/src/App.css b/addon/web/client/src/App.css
index 6c8a22e..29dd23a 100644
--- a/addon/web/client/src/App.css
+++ b/addon/web/client/src/App.css
@@ -56,6 +56,10 @@
margin-left: 10px;
}
+.flow-detail .header-block {
+ margin-bottom: 20px;
+}
+
.flow-detail .header-block > p {
font-weight: bold;
}
diff --git a/addon/web/client/src/App.js b/addon/web/client/src/App.js
index 92a43ac..825be28 100644
--- a/addon/web/client/src/App.js
+++ b/addon/web/client/src/App.js
@@ -63,6 +63,12 @@ class App extends React.Component {
this.flowMgr.add(flow)
this.setState({ flows: this.flowMgr.showList() })
}
+ else if (msg.type === 'requestBody') {
+ const flow = this.flowMgr.get(msg.id)
+ if (!flow) return
+ flow.request.body = msg.content
+ this.setState({ flows: this.state.flows })
+ }
else if (msg.type === 'response') {
const flow = this.flowMgr.get(msg.id)
if (!flow) return
@@ -124,19 +130,21 @@ class App extends React.Component {
-
-
Response Headers
-
- {
- !(response.header) ? null :
- Object.keys(response.header).map(key => {
- return (
-
{key}: {response.header[key].join(' ')}
- )
- })
- }
+ {
+ !(response.header) ? null :
+
+
Response Headers
+
+ {
+ Object.keys(response.header).map(key => {
+ return (
+
{key}: {response.header[key].join(' ')}
+ )
+ })
+ }
+
-
+ }
Request Headers
@@ -151,6 +159,22 @@ class App extends React.Component {
}
+
+ {
+ !(request.body && request.body.byteLength) ? null :
+
+
Request Body
+
+
+ {
+ !(isTextResponse(request)) ? "Not text" :
+ new TextDecoder().decode(request.body)
+ }
+
+
+
+ }
+
}
diff --git a/addon/web/client/src/utils.js b/addon/web/client/src/utils.js
index 10109a1..6bb4b8b 100644
--- a/addon/web/client/src/utils.js
+++ b/addon/web/client/src/utils.js
@@ -25,22 +25,36 @@ export const getSize = response => {
return `${(len/(1024*1024)).toFixed(2)} MB`
}
+const messageEnum = {
+ 'request': 1,
+ 'requestBody': 2,
+ 'response': 3,
+ 'responseBody': 4,
+}
+
+const allMessageBytes = Object.keys(messageEnum).map(k => messageEnum[k])
+
+const messageByteMap = Object.keys(messageEnum).reduce((m, k) => {
+ m[messageEnum[k]] = k
+ return m
+}, {})
+
export const parseMessage = data => {
if (data.byteLength < 39) return null
const meta = new Int8Array(data.slice(0, 3))
const version = meta[0]
if (version !== 1) return null
const type = meta[1]
- if (![1, 2, 3].includes(type)) return null
+ if (!allMessageBytes.includes(type)) return null
const id = new TextDecoder().decode(data.slice(3, 39))
const resp = {
- type: ['request', 'response', 'responseBody'][type-1],
+ type: messageByteMap[type],
id,
waitIntercept: meta[2] === 1,
}
if (data.byteLength === 39) return resp
- if (type === 3) {
+ if (type === messageEnum['requestBody'] || type === messageEnum['responseBody']) {
resp.content = data.slice(39)
return resp
}
diff --git a/addon/web/message.go b/addon/web/message.go
index c90c773..e70f142 100644
--- a/addon/web/message.go
+++ b/addon/web/message.go
@@ -10,20 +10,33 @@ import (
const messageVersion = 1
-type messageType int
+type messageType byte
const (
messageTypeRequest messageType = 1
- messageTypeResponse messageType = 2
- messageTypeResponseBody messageType = 3
+ messageTypeRequestBody messageType = 2
+ messageTypeResponse messageType = 3
+ messageTypeResponseBody messageType = 4
+
+ messageTypeChangeRequest messageType = 11
- messageTypeChangeRequest messageType = 11
messageTypeChangeInterceptUri messageType = 21
)
+var allMessageTypes = []messageType{
+ messageTypeRequest,
+ messageTypeRequestBody,
+ messageTypeResponse,
+ messageTypeResponseBody,
+ messageTypeChangeRequest,
+ messageTypeChangeInterceptUri,
+}
+
func validMessageType(t byte) bool {
- if t == byte(messageTypeRequest) || t == byte(messageTypeResponse) || t == byte(messageTypeResponseBody) || t == byte(messageTypeChangeRequest) || t == byte(messageTypeChangeInterceptUri) {
- return true
+ for _, v := range allMessageTypes {
+ if t == byte(v) {
+ return true
+ }
}
return false
}
@@ -72,6 +85,10 @@ func newMessageRequest(f *flow.Flow) *message {
return newMessage(messageTypeRequest, f.Id, content)
}
+func newMessageRequestBody(f *flow.Flow) *message {
+ return newMessage(messageTypeRequestBody, f.Id, f.Request.Body)
+}
+
func newMessageResponse(f *flow.Flow) *message {
content, err := json.Marshal(f.Response)
if err != nil {
diff --git a/addon/web/web.go b/addon/web/web.go
index e47ce0e..bf17e27 100644
--- a/addon/web/web.go
+++ b/addon/web/web.go
@@ -113,12 +113,18 @@ func (web *WebAddon) sendFlow(f *flow.Flow, msgFn func() *message) bool {
return true
}
-func (web *WebAddon) Request(f *flow.Flow) {
+func (web *WebAddon) Requestheaders(f *flow.Flow) {
web.sendFlow(f, func() *message {
return newMessageRequest(f)
})
}
+func (web *WebAddon) Request(f *flow.Flow) {
+ web.sendFlow(f, func() *message {
+ return newMessageRequestBody(f)
+ })
+}
+
func (web *WebAddon) Responseheaders(f *flow.Flow) {
web.sendFlow(f, func() *message {
return newMessageResponse(f)