Update entries_controller.go

This commit is contained in:
RamiBerm 2021-07-05 13:45:58 +03:00
parent fc03ba2eda
commit 93714ab902

View File

@ -10,6 +10,7 @@ import (
"mizuserver/pkg/up9" "mizuserver/pkg/up9"
"mizuserver/pkg/utils" "mizuserver/pkg/utils"
"mizuserver/pkg/validation" "mizuserver/pkg/validation"
"strings"
"time" "time"
) )
@ -88,9 +89,17 @@ func GetHARs(c *fiber.Ctx) error {
for _, entryData := range entries { for _, entryData := range entries {
var harEntry har.Entry var harEntry har.Entry
_ = json.Unmarshal([]byte(entryData.Entry), &harEntry) _ = json.Unmarshal([]byte(entryData.Entry), &harEntry)
if entryData.ResolvedDestination != "" {
harEntry.Request.URL = utils.SetHostname(harEntry.Request.URL, entryData.ResolvedDestination)
}
sourceOfEntry := entryData.ResolvedSource sourceOfEntry := entryData.ResolvedSource
fileName := fmt.Sprintf("%s.har", sourceOfEntry) if sourceOfEntry != "" {
// naively assumes the proper service source is http
sourceOfEntry = fmt.Sprintf("http://%s", sourceOfEntry)
}
//replace / from the file name cause they end up creating a corrupted folder
fileName := fmt.Sprintf("%s.har", strings.ReplaceAll(sourceOfEntry, "/", "_"))
if harOfSource, ok := harsObject[fileName]; ok { if harOfSource, ok := harsObject[fileName]; ok {
harOfSource.Log.Entries = append(harOfSource.Log.Entries, &harEntry) harOfSource.Log.Entries = append(harOfSource.Log.Entries, &harEntry)
} else { } else {
@ -104,11 +113,14 @@ func GetHARs(c *fiber.Ctx) error {
Name: "mizu", Name: "mizu",
Version: "0.0.2", Version: "0.0.2",
}, },
Source: sourceOfEntry,
}, },
Entries: entriesHar, Entries: entriesHar,
}, },
} }
// leave undefined when no source is present, otherwise modeler assumes source is empty string ""
if sourceOfEntry != "" {
harsObject[fileName].Log.Creator.Source = sourceOfEntry
}
} }
} }