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

Commit bbee8e8

Browse files
author
Marcus Rosén
committed
Added support for multi value query string parameters
Added tests for only multi value query string parameters and multi value query string parameters in combination with query string parameters Updated aws-lambda-go dependency
1 parent 5e02399 commit bbee8e8

3 files changed

Lines changed: 83 additions & 10 deletions

File tree

core/request.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,23 @@ func (r *RequestAccessor) ProxyEventToHTTPRequest(req events.APIGatewayProxyRequ
130130
queryCnt++
131131
}
132132
}
133+
if len(req.MultiValueQueryStringParameters) > 0 {
134+
queryDelim := "&"
135+
queryStart := false
136+
if queryString == "" {
137+
queryDelim = "?"
138+
queryStart = true
139+
}
140+
for q, l := range req.MultiValueQueryStringParameters {
141+
for _, v := range l {
142+
queryString += queryDelim + url.QueryEscape(q) + "=" + url.QueryEscape(v)
143+
if queryStart {
144+
queryDelim = "&"
145+
queryStart = false
146+
}
147+
}
148+
}
149+
}
133150

134151
path := req.Path
135152
if r.stripBasePath != "" && len(r.stripBasePath) > 1 {

core/request_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,62 @@ var _ = Describe("RequestAccessor tests", func() {
7878
Expect("2").To(Equal(query["world"][0]))
7979
})
8080

81+
mvqsRequest := getProxyRequest("/hello", "GET")
82+
mvqsRequest.MultiValueQueryStringParameters = map[string][]string{
83+
"hello": {"1", "2"},
84+
"world": {"3", "4"},
85+
}
86+
It("Populates multi value query string correctly", func() {
87+
httpReq, err := accessor.ProxyEventToHTTPRequest(mvqsRequest)
88+
Expect(err).To(BeNil())
89+
Expect("/hello").To(Equal(httpReq.URL.Path))
90+
Expect("GET").To(Equal(httpReq.Method))
91+
92+
query := httpReq.URL.Query()
93+
Expect(2).To(Equal(len(query)))
94+
Expect(query["hello"]).ToNot(BeNil())
95+
Expect(query["world"]).ToNot(BeNil())
96+
Expect(2).To(Equal(len(query["hello"])))
97+
Expect(2).To(Equal(len(query["world"])))
98+
Expect("1").To(Equal(query["hello"][0]))
99+
Expect("2").To(Equal(query["hello"][1]))
100+
Expect("3").To(Equal(query["world"][0]))
101+
Expect("4").To(Equal(query["world"][1]))
102+
})
103+
104+
qsAndMVQSRequest := getProxyRequest("/hello", "GET")
105+
qsAndMVQSRequest.QueryStringParameters = map[string]string{
106+
"hello1": "1",
107+
"world1": "2",
108+
}
109+
qsAndMVQSRequest.MultiValueQueryStringParameters = map[string][]string{
110+
"hello2": {"3", "4"},
111+
"world2": {"5", "6"},
112+
}
113+
It("Populates query string and multi value query string correctly", func() {
114+
httpReq, err := accessor.ProxyEventToHTTPRequest(qsAndMVQSRequest)
115+
Expect(err).To(BeNil())
116+
Expect("/hello").To(Equal(httpReq.URL.Path))
117+
Expect("GET").To(Equal(httpReq.Method))
118+
119+
query := httpReq.URL.Query()
120+
Expect(4).To(Equal(len(query)))
121+
Expect(query["hello1"]).ToNot(BeNil())
122+
Expect(query["world1"]).ToNot(BeNil())
123+
Expect(query["hello2"]).ToNot(BeNil())
124+
Expect(query["world2"]).ToNot(BeNil())
125+
Expect(1).To(Equal(len(query["hello1"])))
126+
Expect(1).To(Equal(len(query["world1"])))
127+
Expect(2).To(Equal(len(query["hello2"])))
128+
Expect(2).To(Equal(len(query["world2"])))
129+
Expect("1").To(Equal(query["hello1"][0]))
130+
Expect("2").To(Equal(query["world1"][0]))
131+
Expect("3").To(Equal(query["hello2"][0]))
132+
Expect("4").To(Equal(query["hello2"][1]))
133+
Expect("5").To(Equal(query["world2"][0]))
134+
Expect("6").To(Equal(query["world2"][1]))
135+
})
136+
81137
basePathRequest := getProxyRequest("/app1/orders", "GET")
82138

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

vendor/vendor.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
"ignore": "test",
44
"package": [
55
{
6-
"checksumSHA1": "6nfly5ibFQnlDU6IpeFaZZ2q1w0=",
6+
"checksumSHA1": "60T22joBzjxNa8yKzW0V4egimZI=",
77
"path": "github.com/aws/aws-lambda-go/events",
8-
"revision": "5fea2b254568d4043f23d27471ae265cd33d3530",
9-
"revisionTime": "2018-01-26T03:40:30Z"
8+
"revision": "dcf76fe64fb68bc66dd3522c904ccf5ff1b2710a",
9+
"revisionTime": "2019-01-29T19:04:57Z"
1010
},
1111
{
12-
"checksumSHA1": "uI0hFuHj5Amsq+6TzWcczBIdWZY=",
12+
"checksumSHA1": "trfV9u2UzDAypLfWLdFApLNWj0k=",
1313
"path": "github.com/aws/aws-lambda-go/lambda",
14-
"revision": "5fea2b254568d4043f23d27471ae265cd33d3530",
15-
"revisionTime": "2018-01-26T03:40:30Z"
14+
"revision": "dcf76fe64fb68bc66dd3522c904ccf5ff1b2710a",
15+
"revisionTime": "2019-01-29T19:04:57Z"
1616
},
1717
{
1818
"checksumSHA1": "d4ehJWLS4YsqFG825pgwdvKDB6A=",
1919
"path": "github.com/aws/aws-lambda-go/lambda/messages",
20-
"revision": "5fea2b254568d4043f23d27471ae265cd33d3530",
21-
"revisionTime": "2018-01-26T03:40:30Z"
20+
"revision": "dcf76fe64fb68bc66dd3522c904ccf5ff1b2710a",
21+
"revisionTime": "2019-01-29T19:04:57Z"
2222
},
2323
{
2424
"checksumSHA1": "f9MhOwQHveaPVWO6trwfqHa+W0M=",
2525
"path": "github.com/aws/aws-lambda-go/lambdacontext",
26-
"revision": "5fea2b254568d4043f23d27471ae265cd33d3530",
27-
"revisionTime": "2018-01-26T03:40:30Z"
26+
"revision": "dcf76fe64fb68bc66dd3522c904ccf5ff1b2710a",
27+
"revisionTime": "2019-01-29T19:04:57Z"
2828
},
2929
{
3030
"checksumSHA1": "QeKwBtN2df+j+4stw3bQJ6yO4EY=",

0 commit comments

Comments
 (0)