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

Re-add handling of single value headers #55

Merged
merged 18 commits into from
Feb 4, 2020
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
7 changes: 7 additions & 0 deletions core/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,15 @@ func (r *ProxyResponseWriter) GetProxyResponse() (events.APIGatewayProxyResponse
isBase64 = true
}

proxyHeaders := make(map[string]string)

for h := range r.headers {
proxyHeaders[h] = r.headers.Get(h)
}

return events.APIGatewayProxyResponse{
StatusCode: r.status,
Headers: proxyHeaders,
MultiValueHeaders: http.Header(r.headers),
Body: output,
IsBase64Encoded: isBase64,
Expand Down
8 changes: 4 additions & 4 deletions core/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ var _ = Describe("ResponseWriter tests", func() {
proxyResponse, err := response.GetProxyResponse()
Expect(err).To(BeNil())

// Headers are not written to `Headers` field
Expect(0).To(Equal(len(proxyResponse.Headers)))
// Headers are also written to `Headers` field
Expect(1).To(Equal(len(proxyResponse.Headers)))
Expect(1).To(Equal(len(proxyResponse.MultiValueHeaders["Content-Type"])))
Expect("application/json").To(Equal(proxyResponse.MultiValueHeaders["Content-Type"][0]))
})
Expand All @@ -167,8 +167,8 @@ var _ = Describe("ResponseWriter tests", func() {
proxyResponse, err := response.GetProxyResponse()
Expect(err).To(BeNil())

// Headers are not written to `Headers` field
Expect(0).To(Equal(len(proxyResponse.Headers)))
// Headers are also written to `Headers` field
Expect(2).To(Equal(len(proxyResponse.Headers)))

// There are two headers here because Content-Type is always written implicitly
Expect(2).To(Equal(len(proxyResponse.MultiValueHeaders["Set-Cookie"])))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/json-iterator/go v0.0.0-20180128142709-bca911dae073
github.com/kardianos/govendor v1.0.9 // indirect
github.com/kataras/golog v0.0.0-20190624001437-99c81de45f40 // indirect
github.com/kataras/iris v11.1.1+incompatible // indirect
github.com/kataras/iris v11.1.1+incompatible
github.com/kataras/pio v0.0.0-20190103105442-ea782b38602d // indirect
github.com/klauspost/compress v1.7.4 // indirect
github.com/klauspost/cpuid v1.2.1 // indirect
Expand Down