Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions core/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ func (r *RequestAccessor) EventToRequest(req events.APIGatewayProxyRequest) (*ht
}
}
path += "?" + queryString
} else if len(req.QueryStringParameters) > 0 {
// Support `QueryStringParameters` for backward compatibility.
// https://github.com/awslabs/aws-lambda-go-api-proxy/issues/37
queryString := ""
for q := range req.QueryStringParameters {
if queryString != "" {
queryString += "&"
}
queryString += url.QueryEscape(q) + "=" + url.QueryEscape(req.QueryStringParameters[q])
}
path += "?" + queryString
}

httpRequest, err := http.NewRequest(
Expand Down
35 changes: 31 additions & 4 deletions core/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ var _ = Describe("RequestAccessor tests", func() {
Expect(binaryBody).To(Equal(bodyBytes))
})

qsRequest := getProxyRequest("/hello", "GET")
qsRequest.MultiValueQueryStringParameters = map[string][]string{
mqsRequest := getProxyRequest("/hello", "GET")
mqsRequest.MultiValueQueryStringParameters = map[string][]string{
"hello": {"1"},
"world": {"2", "3"},
}
It("Populates query string correctly", func() {
httpReq, err := accessor.EventToRequestWithContext(context.Background(), qsRequest)
mqsRequest.QueryStringParameters = map[string]string{
"hello": "1",
"world": "2",
}
It("Populates multiple value query string correctly", func() {
httpReq, err := accessor.EventToRequestWithContext(context.Background(), mqsRequest)
Expect(err).To(BeNil())
Expect("/hello").To(Equal(httpReq.URL.Path))
Expect("GET").To(Equal(httpReq.Method))
Expand All @@ -82,6 +86,29 @@ var _ = Describe("RequestAccessor tests", func() {
Expect("3").To(Equal(query["world"][1]))
})

// Support `QueryStringParameters` for backward compatibility.
// https://github.com/awslabs/aws-lambda-go-api-proxy/issues/37
qsRequest := getProxyRequest("/hello", "GET")
qsRequest.QueryStringParameters = map[string]string{
"hello": "1",
"world": "2",
}
It("Populates query string correctly", func() {
httpReq, err := accessor.EventToRequestWithContext(context.Background(), qsRequest)
Expect(err).To(BeNil())
Expect("/hello").To(Equal(httpReq.URL.Path))
Expect("GET").To(Equal(httpReq.Method))

query := httpReq.URL.Query()
Expect(2).To(Equal(len(query)))
Expect(query["hello"]).ToNot(BeNil())
Expect(query["world"]).ToNot(BeNil())
Expect(1).To(Equal(len(query["hello"])))
Expect(1).To(Equal(len(query["world"])))
Expect("1").To(Equal(query["hello"][0]))
Expect("2").To(Equal(query["world"][0]))
})

basePathRequest := getProxyRequest("/app1/orders", "GET")

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