Show HTTP path segments as a list of strings in the right pane (#641)

* Show HTTP path segments as a list of strings in the right pane

* Use better variable names
This commit is contained in:
M. Mert Yıldıran 2022-01-16 09:43:52 +03:00 committed by GitHub
parent 4db8e8902b
commit 59fbe4c479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 4 deletions

View File

@ -3,14 +3,15 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"strconv"
"github.com/up9inc/mizu/tap/api" "github.com/up9inc/mizu/tap/api"
) )
func mapSliceRebuildAsMap(mapSlice []interface{}) (newMap map[string]interface{}) { func mapSliceRebuildAsMap(mapSlice []interface{}) (newMap map[string]interface{}) {
newMap = make(map[string]interface{}) newMap = make(map[string]interface{})
for _, header := range mapSlice { for _, item := range mapSlice {
h := header.(map[string]interface{}) h := item.(map[string]interface{})
newMap[h["name"].(string)] = h["value"] newMap[h["name"].(string)] = h["value"]
} }
@ -19,8 +20,8 @@ func mapSliceRebuildAsMap(mapSlice []interface{}) (newMap map[string]interface{}
func representMapSliceAsTable(mapSlice []interface{}, selectorPrefix string) (representation string) { func representMapSliceAsTable(mapSlice []interface{}, selectorPrefix string) (representation string) {
var table []api.TableData var table []api.TableData
for _, header := range mapSlice { for _, item := range mapSlice {
h := header.(map[string]interface{}) h := item.(map[string]interface{})
selector := fmt.Sprintf("%s[\"%s\"]", selectorPrefix, h["name"].(string)) selector := fmt.Sprintf("%s[\"%s\"]", selectorPrefix, h["name"].(string))
table = append(table, api.TableData{ table = append(table, api.TableData{
Name: h["name"].(string), Name: h["name"].(string),
@ -33,3 +34,19 @@ func representMapSliceAsTable(mapSlice []interface{}, selectorPrefix string) (re
representation = string(obj) representation = string(obj)
return return
} }
func representSliceAsTable(slice []interface{}, selectorPrefix string) (representation string) {
var table []api.TableData
for i, item := range slice {
selector := fmt.Sprintf("%s[%d]", selectorPrefix, i)
table = append(table, api.TableData{
Name: strconv.Itoa(i),
Value: item.(interface{}),
Selector: selector,
})
}
obj, _ := json.Marshal(table)
representation = string(obj)
return
}

View File

@ -9,6 +9,7 @@ import (
"log" "log"
"net/http" "net/http"
"net/url" "net/url"
"strings"
"time" "time"
"github.com/up9inc/mizu/tap/api" "github.com/up9inc/mizu/tap/api"
@ -209,6 +210,7 @@ func (d dissecting) Analyze(item *api.OutputChannelItem, resolvedSource string,
request["url"] = reqDetails["url"].(string) request["url"] = reqDetails["url"].(string)
reqDetails["targetUri"] = reqDetails["url"] reqDetails["targetUri"] = reqDetails["url"]
reqDetails["path"] = path reqDetails["path"] = path
reqDetails["pathSegments"] = strings.Split(path, "/")[1:]
reqDetails["summary"] = path reqDetails["summary"] = path
// Rearrange the maps for the querying // Rearrange the maps for the querying
@ -296,6 +298,15 @@ func representRequest(request map[string]interface{}) (repRequest []interface{})
Data: string(details), Data: string(details),
}) })
pathSegments := request["pathSegments"].([]interface{})
if len(pathSegments) > 1 {
repRequest = append(repRequest, api.SectionData{
Type: api.TABLE,
Title: "Path Segments",
Data: representSliceAsTable(pathSegments, `request.pathSegments`),
})
}
repRequest = append(repRequest, api.SectionData{ repRequest = append(repRequest, api.SectionData{
Type: api.TABLE, Type: api.TABLE,
Title: "Headers", Title: "Headers",