Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Mizu
Commits
c2a4bace
Commit
c2a4bace
authored
2 years ago
by
Roy Island
Browse files
Options
Download
Email Patches
Plain Diff
fix
parent
3463ce7d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
agent/pkg/har/utils.go
+2
-45
agent/pkg/har/utils.go
tap/extensions/http/helpers.go
+10
-12
tap/extensions/http/helpers.go
with
12 additions
and
57 deletions
+12
-57
agent/pkg/har/utils.go
+
2
-
45
View file @
c2a4bace
...
...
@@ -11,49 +11,6 @@ import (
"github.com/up9inc/mizu/logger"
)
// Keep it because we might want cookies in the future
//func BuildCookies(rawCookies []interface{}) []har.Cookie {
// cookies := make([]har.Cookie, 0, len(rawCookies))
//
// for _, cookie := range rawCookies {
// c := cookie.(map[string]interface{})
// expiresStr := ""
// if c["expires"] != nil {
// expiresStr = c["expires"].(string)
// }
// expires, _ := time.Parse(time.RFC3339, expiresStr)
// httpOnly := false
// if c["httponly"] != nil {
// httpOnly, _ = strconv.ParseBool(c["httponly"].(string))
// }
// secure := false
// if c["secure"] != nil {
// secure, _ = strconv.ParseBool(c["secure"].(string))
// }
// path := ""
// if c["path"] != nil {
// path = c["path"].(string)
// }
// domain := ""
// if c["domain"] != nil {
// domain = c["domain"].(string)
// }
//
// cookies = append(cookies, har.Cookie{
// Name: c["name"].(string),
// Value: c["value"].(string),
// Path: path,
// Domain: domain,
// HTTPOnly: httpOnly,
// Secure: secure,
// Expires: expires,
// Expires8601: expiresStr,
// })
// }
//
// return cookies
//}
func
BuildHeaders
(
rawHeaders
map
[
string
]
interface
{})
([]
Header
,
string
,
string
,
string
,
string
,
string
)
{
var
host
,
scheme
,
authority
,
path
,
status
string
headers
:=
make
([]
Header
,
0
,
len
(
rawHeaders
))
...
...
@@ -118,7 +75,7 @@ func BuildPostParams(rawParams []interface{}) []Param {
func
NewRequest
(
request
map
[
string
]
interface
{})
(
harRequest
*
Request
,
err
error
)
{
headers
,
host
,
scheme
,
authority
,
path
,
_
:=
BuildHeaders
(
request
[
"headers"
]
.
(
map
[
string
]
interface
{}))
cookies
:=
make
([]
Cookie
,
0
)
// BuildCookies(request["cookies"].(map[string]interface{}))
cookies
:=
make
([]
Cookie
,
0
)
postData
,
_
:=
request
[
"postData"
]
.
(
map
[
string
]
interface
{})
mimeType
:=
postData
[
"mimeType"
]
...
...
@@ -179,7 +136,7 @@ func NewRequest(request map[string]interface{}) (harRequest *Request, err error)
func
NewResponse
(
response
map
[
string
]
interface
{})
(
harResponse
*
Response
,
err
error
)
{
headers
,
_
,
_
,
_
,
_
,
_status
:=
BuildHeaders
(
response
[
"headers"
]
.
(
map
[
string
]
interface
{}))
cookies
:=
make
([]
Cookie
,
0
)
// BuildCookies(response["cookies"].(map[string]interface{}))
cookies
:=
make
([]
Cookie
,
0
)
content
,
_
:=
response
[
"content"
]
.
(
map
[
string
]
interface
{})
mimeType
:=
content
[
"mimeType"
]
...
...
This diff is collapsed.
Click to expand it.
tap/extensions/http/helpers.go
+
10
-
12
View file @
c2a4bace
...
...
@@ -75,9 +75,7 @@ func mapSliceMergeRepeatedKeys(mapSlice []interface{}) (newMapSlice []interface{
func
representMapAsTable
(
mapToTable
map
[
string
]
interface
{},
selectorPrefix
string
)
(
representation
string
)
{
var
table
[]
api
.
TableData
for
key
,
value
:=
range
mapToTable
{
if
tableData
:=
createTableData
(
key
,
value
,
selectorPrefix
);
tableData
!=
nil
{
table
=
append
(
table
,
*
tableData
)
}
table
=
append
(
table
,
createTableForKey
(
key
,
value
,
selectorPrefix
)
...
)
}
obj
,
_
:=
json
.
Marshal
(
table
)
...
...
@@ -92,9 +90,7 @@ func representMapSliceAsTable(mapSlice []interface{}, selectorPrefix string) (re
key
:=
h
[
"name"
]
.
(
string
)
value
:=
h
[
"value"
]
if
tableData
:=
createTableData
(
key
,
value
,
selectorPrefix
);
tableData
!=
nil
{
table
=
append
(
table
,
*
tableData
)
}
table
=
append
(
table
,
createTableForKey
(
key
,
value
,
selectorPrefix
)
...
)
}
obj
,
_
:=
json
.
Marshal
(
table
)
...
...
@@ -102,7 +98,9 @@ func representMapSliceAsTable(mapSlice []interface{}, selectorPrefix string) (re
return
}
func
createTableData
(
key
string
,
value
interface
{},
selectorPrefix
string
)
*
api
.
TableData
{
func
createTableForKey
(
key
string
,
value
interface
{},
selectorPrefix
string
)
[]
api
.
TableData
{
var
table
[]
api
.
TableData
var
reflectKind
reflect
.
Kind
reflectType
:=
reflect
.
TypeOf
(
value
)
if
reflectType
==
nil
{
...
...
@@ -117,22 +115,22 @@ func createTableData(key string, value interface{}, selectorPrefix string) *api.
case
reflect
.
Array
:
for
i
,
el
:=
range
value
.
([]
interface
{})
{
selector
:=
fmt
.
Sprintf
(
"%s.%s[%d]"
,
selectorPrefix
,
key
,
i
)
return
&
api
.
TableData
{
table
=
append
(
table
,
api
.
TableData
{
Name
:
fmt
.
Sprintf
(
"%s [%d]"
,
key
,
i
),
Value
:
el
,
Selector
:
selector
,
}
}
)
}
default
:
selector
:=
fmt
.
Sprintf
(
"%s[
\"
%s
\"
]"
,
selectorPrefix
,
key
)
return
&
api
.
TableData
{
table
=
append
(
table
,
api
.
TableData
{
Name
:
key
,
Value
:
value
,
Selector
:
selector
,
}
}
)
}
return
nil
return
table
}
func
representSliceAsTable
(
slice
[]
interface
{},
selectorPrefix
string
)
(
representation
string
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help