|
|
@ -10,21 +10,34 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
const messageVersion = 1
|
|
|
|
const messageVersion = 1
|
|
|
|
|
|
|
|
|
|
|
|
type messageType int
|
|
|
|
type messageType byte
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
const (
|
|
|
|
messageTypeRequest messageType = 1
|
|
|
|
messageTypeRequest messageType = 1
|
|
|
|
messageTypeResponse messageType = 2
|
|
|
|
messageTypeRequestBody messageType = 2
|
|
|
|
messageTypeResponseBody messageType = 3
|
|
|
|
messageTypeResponse messageType = 3
|
|
|
|
|
|
|
|
messageTypeResponseBody messageType = 4
|
|
|
|
|
|
|
|
|
|
|
|
messageTypeChangeRequest messageType = 11
|
|
|
|
messageTypeChangeRequest messageType = 11
|
|
|
|
|
|
|
|
|
|
|
|
messageTypeChangeInterceptUri messageType = 21
|
|
|
|
messageTypeChangeInterceptUri messageType = 21
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var allMessageTypes = []messageType{
|
|
|
|
|
|
|
|
messageTypeRequest,
|
|
|
|
|
|
|
|
messageTypeRequestBody,
|
|
|
|
|
|
|
|
messageTypeResponse,
|
|
|
|
|
|
|
|
messageTypeResponseBody,
|
|
|
|
|
|
|
|
messageTypeChangeRequest,
|
|
|
|
|
|
|
|
messageTypeChangeInterceptUri,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func validMessageType(t byte) bool {
|
|
|
|
func validMessageType(t byte) bool {
|
|
|
|
if t == byte(messageTypeRequest) || t == byte(messageTypeResponse) || t == byte(messageTypeResponseBody) || t == byte(messageTypeChangeRequest) || t == byte(messageTypeChangeInterceptUri) {
|
|
|
|
for _, v := range allMessageTypes {
|
|
|
|
|
|
|
|
if t == byte(v) {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -72,6 +85,10 @@ func newMessageRequest(f *flow.Flow) *message {
|
|
|
|
return newMessage(messageTypeRequest, f.Id, content)
|
|
|
|
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 {
|
|
|
|
func newMessageResponse(f *flow.Flow) *message {
|
|
|
|
content, err := json.Marshal(f.Response)
|
|
|
|
content, err := json.Marshal(f.Response)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|