Skip to content

Commit

Permalink
Set json content type in API GW response when using ctx.JSON() (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
steinfletcher authored Jan 13, 2021
1 parent 034c615 commit e2d63e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apigw_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func (c *APIGatewayProxyContext) JSON(statusCode int, body interface{}) error {
if err != nil {
return err
}

if c.Response.Headers == nil {
c.Response.Headers = make(map[string]string)
}
c.Response.Headers["Content-Type"] = "application/json"
}
c.Response.StatusCode = statusCode
c.Response.Body = string(b)
Expand Down
1 change: 1 addition & 0 deletions apigw_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func TestAPIGatewayProxyContext_JSON(t *testing.T) {
},
expectedRes: events.APIGatewayProxyResponse{
StatusCode: 200,
Headers: map[string]string{"Content-Type": "application/json"},
Body: `{"name":"one","status":"ok"}`,
},
},
Expand Down

0 comments on commit e2d63e5

Please sign in to comment.