MCPcopy
hub / github.com/keploy/keploy / AddHTTPBodyToMap

Function AddHTTPBodyToMap

pkg/matcher/utils.go:1541–1563  ·  view source on GitHub ↗

func CheckStringExist(s string, mp map[string][]string) ([]string, bool) { if val, ok := mp[s]; ok { return val, ok } return []string{}, false }

(body string, m map[string][]string)

Source from the content-addressed store, hash-verified

1539// }
1540
1541func AddHTTPBodyToMap(body string, m map[string][]string) error {
1542 // add body
1543 if json.Valid([]byte(body)) {
1544 var result interface{}
1545
1546 err := json.Unmarshal([]byte(body), &result)
1547 if err != nil {
1548 return err
1549 }
1550 j := Flatten(result)
1551 for k, v := range j {
1552 nk := "body"
1553 if k != "" {
1554 nk = nk + "." + k
1555 }
1556 m[nk] = v
1557 }
1558 } else {
1559 // add it as raw text
1560 m["body"] = []string{body}
1561 }
1562 return nil
1563}
1564
1565// Flatten takes a map and returns a new one where nested maps are replaced
1566// by dot-delimited keys.

Callers

nothing calls this directly

Calls 3

ValidMethod · 0.80
UnmarshalMethod · 0.80
FlattenFunction · 0.70

Tested by

no test coverage detected