Skip to content

Commit

Permalink
Merge pull request #21 from twharmon/content-type-json
Browse files Browse the repository at this point in the history
Content type json
  • Loading branch information
twharmon authored Aug 24, 2022
2 parents 9c7bbac + e17cffc commit d0867df
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
7 changes: 6 additions & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ func (c *handlerContext) Request() Request {
}

func (c *handlerContext) Response(status int, body ...interface{}) Responder {
r := response{status: status}
r := response{
status: status,
headers: map[string]string{
"content-type": "application/json",
},
}
if len(body) > 0 {
r.body = body[0]
}
Expand Down
2 changes: 2 additions & 0 deletions golamb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestGetHandler(t *testing.T) {
}
want := events.APIGatewayV2HTTPResponse{
StatusCode: http.StatusOK,
Headers: map[string]string{"content-type": "application/json"},
}
if !reflect.DeepEqual(want, got) {
t.Fatalf("want %v; got %v", want, got)
Expand Down Expand Up @@ -59,6 +60,7 @@ func TestPanicHandler(t *testing.T) {
}
want := &events.APIGatewayV2HTTPResponse{
StatusCode: http.StatusInternalServerError,
Headers: map[string]string{"content-type": "application/json"},
}
if !reflect.DeepEqual(want, got) {
t.Fatalf("want %v; got %v", want, got)
Expand Down
3 changes: 0 additions & 3 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ func (r *response) Respond() (*events.APIGatewayV2HTTPResponse, error) {
}

func (r *response) SetHeader(key string, value string) Responder {
if r.headers == nil {
r.headers = make(map[string]string)
}
r.headers[key] = value
return r
}
Expand Down
8 changes: 7 additions & 1 deletion response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestResponseOKEmpty(t *testing.T) {
}
want := &events.APIGatewayV2HTTPResponse{
StatusCode: http.StatusOK,
Headers: map[string]string{"content-type": "application/json"},
}
if !reflect.DeepEqual(want, got) {
t.Fatalf("want %v; got %v", want, got)
Expand All @@ -35,6 +36,7 @@ func TestResponseOKBody(t *testing.T) {
want := &events.APIGatewayV2HTTPResponse{
StatusCode: http.StatusOK,
Body: `{"foo":"bar"}`,
Headers: map[string]string{"content-type": "application/json"},
}
if !reflect.DeepEqual(want, got) {
t.Fatalf("want %v; got %v", want, got)
Expand All @@ -51,7 +53,10 @@ func TestResponseOKHeader(t *testing.T) {
}
want := &events.APIGatewayV2HTTPResponse{
StatusCode: http.StatusOK,
Headers: map[string]string{"foo": "bar"},
Headers: map[string]string{
"foo": "bar",
"content-type": "application/json",
},
}
if !reflect.DeepEqual(want, got) {
t.Fatalf("want %v; got %v", want, got)
Expand All @@ -69,6 +74,7 @@ func TestResponseOKCookie(t *testing.T) {
want := &events.APIGatewayV2HTTPResponse{
StatusCode: http.StatusOK,
Cookies: []string{"foo=bar"},
Headers: map[string]string{"content-type": "application/json"},
}
if !reflect.DeepEqual(want, got) {
t.Fatalf("want %v; got %v", want, got)
Expand Down

0 comments on commit d0867df

Please sign in to comment.