From 54c2a4c1c7fa5a00318a041413cc1f478a38377b 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 | 21 ++++++++++++++++++--- integration/integration_test.go | 1 - 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/backend/controller/ingress/request.go b/backend/controller/ingress/request.go index 6d243a49db..79d9f7d452 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,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 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`.