From 6a2ec0c838999ac16c9e2552914b86f1043f2a27 Mon Sep 17 00:00:00 2001 From: Wes Date: Tue, 13 Feb 2024 08:51:40 -0700 Subject: [PATCH] fix: map types on request and array aliasing --- backend/controller/ingress/request.go | 27 ++++++++++++++++++++++++--- integration/integration_test.go | 1 - 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/backend/controller/ingress/request.go b/backend/controller/ingress/request.go index 6d243a49db..458e73b784 100644 --- a/backend/controller/ingress/request.go +++ b/backend/controller/ingress/request.go @@ -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 }) @@ -41,12 +41,33 @@ func BuildRequestBody(route *dal.IngressRoute, r *http.Request, sch *schema.Sche return nil, err } + // Since the query and header parameters are a `map[string][]string` + // we need to convert them before they go through the `transformFromAliasedFields` call + // otherwise they will fail the type check. + queryMap := make(map[string]any) + for key, values := range r.URL.Query() { + valuesAny := make([]any, len(values)) + for i, v := range values { + valuesAny[i] = v + } + queryMap[key] = valuesAny + } + + 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 diff --git a/integration/integration_test.go b/integration/integration_test.go index a0dcf8749f..24a59bb36f 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -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`.