mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-10 12:53:37 +00:00
Fix the issues in summary section of details layout for HTTP/2 (gRPC) protocol
This commit is contained in:
parent
e90fd58d5e
commit
6f84138eb7
@ -103,7 +103,13 @@ func (d dissecting) Dissect(b *bufio.Reader, isClient bool, tcpID *api.TcpID, em
|
|||||||
|
|
||||||
func (d dissecting) Analyze(item *api.OutputChannelItem, entryId string, resolvedSource string, resolvedDestination string) *api.MizuEntry {
|
func (d dissecting) Analyze(item *api.OutputChannelItem, entryId string, resolvedSource string, resolvedDestination string) *api.MizuEntry {
|
||||||
var host, scheme, authority, path, service string
|
var host, scheme, authority, path, service string
|
||||||
for _, header := range item.Pair.Request.Payload.(map[string]interface{})["headers"].([]interface{}) {
|
|
||||||
|
request := item.Pair.Request.Payload.(map[string]interface{})
|
||||||
|
response := item.Pair.Response.Payload.(map[string]interface{})
|
||||||
|
reqDetails := request["details"].(map[string]interface{})
|
||||||
|
resDetails := response["details"].(map[string]interface{})
|
||||||
|
|
||||||
|
for _, header := range reqDetails["headers"].([]interface{}) {
|
||||||
h := header.(map[string]interface{})
|
h := header.(map[string]interface{})
|
||||||
if h["name"] == "Host" {
|
if h["name"] == "Host" {
|
||||||
host = h["value"].(string)
|
host = h["value"].(string)
|
||||||
@ -118,23 +124,24 @@ func (d dissecting) Analyze(item *api.OutputChannelItem, entryId string, resolve
|
|||||||
path = h["value"].(string)
|
path = h["value"].(string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
request := item.Pair.Request.Payload.(map[string]interface{})
|
|
||||||
response := item.Pair.Response.Payload.(map[string]interface{})
|
|
||||||
entryBytes, _ := json.Marshal(item.Pair)
|
|
||||||
if item.Protocol.Version == "2.0" {
|
if item.Protocol.Version == "2.0" {
|
||||||
service = fmt.Sprintf("(gRPC) %s://%s", scheme, authority)
|
service = fmt.Sprintf("(gRPC) %s://%s", scheme, authority)
|
||||||
} else {
|
} else {
|
||||||
service = fmt.Sprintf("http://%s", host)
|
service = fmt.Sprintf("http://%s", host)
|
||||||
path = request["url"].(string)
|
path = reqDetails["url"].(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
request["url"] = path
|
||||||
|
entryBytes, _ := json.Marshal(item.Pair)
|
||||||
return &api.MizuEntry{
|
return &api.MizuEntry{
|
||||||
ProtocolName: protocol.Name,
|
ProtocolName: protocol.Name,
|
||||||
ProtocolVersion: item.Protocol.Version,
|
ProtocolVersion: item.Protocol.Version,
|
||||||
EntryId: entryId,
|
EntryId: entryId,
|
||||||
Entry: string(entryBytes),
|
Entry: string(entryBytes),
|
||||||
Url: fmt.Sprintf("%s%s", service, path),
|
Url: fmt.Sprintf("%s%s", service, path),
|
||||||
Method: request["method"].(string),
|
Method: reqDetails["method"].(string),
|
||||||
Status: int(response["status"].(float64)),
|
Status: int(resDetails["status"].(float64)),
|
||||||
RequestSenderIp: item.ConnectionInfo.ClientIP,
|
RequestSenderIp: item.ConnectionInfo.ClientIP,
|
||||||
Service: service,
|
Service: service,
|
||||||
Timestamp: item.Timestamp,
|
Timestamp: item.Timestamp,
|
||||||
@ -308,8 +315,10 @@ func (d dissecting) Represent(entry *api.MizuEntry) (api.Protocol, []byte, error
|
|||||||
representation := make(map[string]interface{}, 0)
|
representation := make(map[string]interface{}, 0)
|
||||||
request := root["request"].(map[string]interface{})["payload"].(map[string]interface{})
|
request := root["request"].(map[string]interface{})["payload"].(map[string]interface{})
|
||||||
response := root["response"].(map[string]interface{})["payload"].(map[string]interface{})
|
response := root["response"].(map[string]interface{})["payload"].(map[string]interface{})
|
||||||
repRequest := representRequest(request)
|
reqDetails := request["details"].(map[string]interface{})
|
||||||
repResponse := representResponse(response)
|
resDetails := response["details"].(map[string]interface{})
|
||||||
|
repRequest := representRequest(reqDetails)
|
||||||
|
repResponse := representResponse(resDetails)
|
||||||
representation["request"] = repRequest
|
representation["request"] = repRequest
|
||||||
representation["response"] = repResponse
|
representation["response"] = repResponse
|
||||||
object, err := json.Marshal(representation)
|
object, err := json.Marshal(representation)
|
||||||
|
@ -19,6 +19,12 @@ type HTTPPayloader interface {
|
|||||||
MarshalJSON() ([]byte, error)
|
MarshalJSON() ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HTTPWrapper struct {
|
||||||
|
Method string `json:"method"`
|
||||||
|
Url string `json:"url"`
|
||||||
|
Details interface{} `json:"details"`
|
||||||
|
}
|
||||||
|
|
||||||
func (h HTTPPayload) MarshalJSON() ([]byte, error) {
|
func (h HTTPPayload) MarshalJSON() ([]byte, error) {
|
||||||
switch h.Type {
|
switch h.Type {
|
||||||
case "http_request":
|
case "http_request":
|
||||||
@ -27,14 +33,22 @@ func (h HTTPPayload) MarshalJSON() ([]byte, error) {
|
|||||||
rlog.Debugf("convert-request-to-har", "Failed converting request to HAR %s (%v,%+v)", err, err, err)
|
rlog.Debugf("convert-request-to-har", "Failed converting request to HAR %s (%v,%+v)", err, err, err)
|
||||||
return nil, errors.New("Failed converting request to HAR")
|
return nil, errors.New("Failed converting request to HAR")
|
||||||
}
|
}
|
||||||
return json.Marshal(harRequest)
|
return json.Marshal(&HTTPWrapper{
|
||||||
|
Method: harRequest.Method,
|
||||||
|
Url: "",
|
||||||
|
Details: harRequest,
|
||||||
|
})
|
||||||
case "http_response":
|
case "http_response":
|
||||||
harResponse, err := har.NewResponse(h.Data.(*http.Response), true)
|
harResponse, err := har.NewResponse(h.Data.(*http.Response), true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rlog.Debugf("convert-response-to-har", "Failed converting response to HAR %s (%v,%+v)", err, err, err)
|
rlog.Debugf("convert-response-to-har", "Failed converting response to HAR %s (%v,%+v)", err, err, err)
|
||||||
return nil, errors.New("Failed converting response to HAR")
|
return nil, errors.New("Failed converting response to HAR")
|
||||||
}
|
}
|
||||||
return json.Marshal(harResponse)
|
return json.Marshal(&HTTPWrapper{
|
||||||
|
Method: "",
|
||||||
|
Url: "",
|
||||||
|
Details: harResponse,
|
||||||
|
})
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("HTTP payload cannot be marshaled: %s\n", h.Type))
|
panic(fmt.Sprintf("HTTP payload cannot be marshaled: %s\n", h.Type))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user