Skip to content

Commit

Permalink
fix: map types on request and array aliasing
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbillman committed Feb 13, 2024
1 parent fbfd47f commit 321d49c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
21 changes: 18 additions & 3 deletions backend/controller/ingress/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func BuildRequestBody(route *dal.IngressRoute, r *http.Request, sch *schema.Sche
var requestMap map[string]any

if metadata, ok := verb.GetMetadataIngress().Get(); ok && metadata.Type == "http" {
pathParameters := map[string]string{}
pathParameters := map[string]any{}
matchSegments(route.Path, r.URL.Path, func(segment, value string) {
pathParameters[segment] = value
})
Expand All @@ -41,12 +41,27 @@ func BuildRequestBody(route *dal.IngressRoute, r *http.Request, sch *schema.Sche
return nil, err
}

// convert query and headers to map[string]any for aliasing
queryMap := make(map[string]any)
for key, values := range r.URL.Query() {
queryMap[key] = values
}

headerMap := make(map[string]any)
for key, values := range r.Header {
valuesAny := make([]any, len(values))
for i, v := range values {
valuesAny[i] = v
}
headerMap[key] = valuesAny
}

requestMap = map[string]any{}
requestMap["method"] = r.Method
requestMap["path"] = r.URL.Path
requestMap["pathParameters"] = pathParameters
requestMap["query"] = r.URL.Query()
requestMap["headers"] = r.Header
requestMap["query"] = queryMap
requestMap["headers"] = headerMap
requestMap["body"] = httpRequestBody
} else {
var err error
Expand Down
1 change: 0 additions & 1 deletion integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ func httpCall(rd runtimeData, method string, path string, body []byte, onRespons

bodyBytes, err := io.ReadAll(resp.Body)
assert.NoError(t, err)
fmt.Printf("%s\n", bodyBytes)

var resBody map[string]any
// ignore the error here since some responses are just `[]byte`.
Expand Down

0 comments on commit 321d49c

Please sign in to comment.