Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit 5a7c178

Browse files
tanishikingsapessi
authored andcommitted
Add support for query string parameters again (awslabs#38)
see: awslabs#37
1 parent 8964150 commit 5a7c178

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

core/request.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@ func (r *RequestAccessor) EventToRequest(req events.APIGatewayProxyRequest) (*ht
166166
}
167167
}
168168
path += "?" + queryString
169+
} else if len(req.QueryStringParameters) > 0 {
170+
// Support `QueryStringParameters` for backward compatibility.
171+
// https://github.com/awslabs/aws-lambda-go-api-proxy/issues/37
172+
queryString := ""
173+
for q := range req.QueryStringParameters {
174+
if queryString != "" {
175+
queryString += "&"
176+
}
177+
queryString += url.QueryEscape(q) + "=" + url.QueryEscape(req.QueryStringParameters[q])
178+
}
179+
path += "?" + queryString
169180
}
170181

171182
httpRequest, err := http.NewRequest(

core/request_test.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,17 @@ var _ = Describe("RequestAccessor tests", func() {
6060
Expect(binaryBody).To(Equal(bodyBytes))
6161
})
6262

63-
qsRequest := getProxyRequest("/hello", "GET")
64-
qsRequest.MultiValueQueryStringParameters = map[string][]string{
63+
mqsRequest := getProxyRequest("/hello", "GET")
64+
mqsRequest.MultiValueQueryStringParameters = map[string][]string{
6565
"hello": {"1"},
6666
"world": {"2", "3"},
6767
}
68-
It("Populates query string correctly", func() {
69-
httpReq, err := accessor.EventToRequestWithContext(context.Background(), qsRequest)
68+
mqsRequest.QueryStringParameters = map[string]string{
69+
"hello": "1",
70+
"world": "2",
71+
}
72+
It("Populates multiple value query string correctly", func() {
73+
httpReq, err := accessor.EventToRequestWithContext(context.Background(), mqsRequest)
7074
Expect(err).To(BeNil())
7175
Expect("/hello").To(Equal(httpReq.URL.Path))
7276
Expect("GET").To(Equal(httpReq.Method))
@@ -82,6 +86,29 @@ var _ = Describe("RequestAccessor tests", func() {
8286
Expect("3").To(Equal(query["world"][1]))
8387
})
8488

89+
// Support `QueryStringParameters` for backward compatibility.
90+
// https://github.com/awslabs/aws-lambda-go-api-proxy/issues/37
91+
qsRequest := getProxyRequest("/hello", "GET")
92+
qsRequest.QueryStringParameters = map[string]string{
93+
"hello": "1",
94+
"world": "2",
95+
}
96+
It("Populates query string correctly", func() {
97+
httpReq, err := accessor.EventToRequestWithContext(context.Background(), qsRequest)
98+
Expect(err).To(BeNil())
99+
Expect("/hello").To(Equal(httpReq.URL.Path))
100+
Expect("GET").To(Equal(httpReq.Method))
101+
102+
query := httpReq.URL.Query()
103+
Expect(2).To(Equal(len(query)))
104+
Expect(query["hello"]).ToNot(BeNil())
105+
Expect(query["world"]).ToNot(BeNil())
106+
Expect(1).To(Equal(len(query["hello"])))
107+
Expect(1).To(Equal(len(query["world"])))
108+
Expect("1").To(Equal(query["hello"][0]))
109+
Expect("2").To(Equal(query["world"][0]))
110+
})
111+
85112
basePathRequest := getProxyRequest("/app1/orders", "GET")
86113

87114
It("Stips the base path correct", func() {

0 commit comments

Comments
 (0)