Skip to content

Commit

Permalink
apex#38 ensure that headers and status code get written, even if noth…
Browse files Browse the repository at this point in the history
…ing was ever written. This better aligns with the golang http package's own behavior to write on close.
  • Loading branch information
UnquietCode committed Nov 9, 2020
1 parent 46d1104 commit ffb4021
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions v2/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func (w *ResponseWriter) End() events.APIGatewayV2HTTPResponse {
w.out.Cookies = w.header["Set-Cookie"]
w.header.Del("Set-Cookie")

// ensure headers are written out
w.Write([]byte{})

// notify end
w.closeNotifyCh <- true

Expand Down
9 changes: 9 additions & 0 deletions v2/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,12 @@ func TestResponseWriter_WriteHeader(t *testing.T) {
assert.Equal(t, "Not Found\n", e.Body)
assert.Equal(t, "text/plain; charset=utf8", e.Headers["Content-Type"])
}

func TestResponseWriter_WriteHeadersWhenEmpty(t *testing.T) {
w := NewResponse()
w.Header().Set("Content-Type", "text/xml")

e := w.End()
assert.Equal(t, 200, e.StatusCode)
assert.Equal(t, "text/xml", e.Headers["Content-Type"])
}

0 comments on commit ffb4021

Please sign in to comment.