Skip to content

Commit

Permalink
Merge pull request #8 from shogo82148/status-no-content-does-not-allo…
Browse files Browse the repository at this point in the history
…w-body

Thanks for your great commits.
  • Loading branch information
deadcheat committed Dec 5, 2018
2 parents a0216ac + bf49c34 commit ec70f53
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cors.go
Expand Up @@ -86,7 +86,8 @@ func WithConfig(service *goa.Service, conf *GoaCORSConfig) goa.Middleware {
if conf.MaxAge > 0 {
rw.Header().Set(HeaderAccessControlMaxAge, maxAge)
}
return service.Send(c, http.StatusNoContent, http.StatusText(http.StatusNoContent))
rw.WriteHeader(http.StatusNoContent)
return nil
}
}

Expand Down
17 changes: 17 additions & 0 deletions cors_test.go
Expand Up @@ -220,6 +220,14 @@ func TestPreflightRequet(t *testing.T) {
t.Error("access control allow headers should be 'X-OriginalRequest' but ", rw.Header().Get(goacors.HeaderAccessControlAllowHeaders))
t.Fail()
}

// StatusNoContent does not allow body
if rw.Status != http.StatusNoContent {
t.Errorf("the status should be %d, got %d", http.StatusNoContent, rw.Status)
}
if len(rw.Body) != 0 {
t.Errorf("the length of the body should be 0, got %d", len(rw.Body))
}
}

func TestNotGivenAllowHeaderOnRequest(t *testing.T) {
Expand Down Expand Up @@ -325,4 +333,13 @@ func TestAddedAllowOrigHeader(t *testing.T) {
t.Error("allow origin should be empty")
t.Fail()
}

// StatusNoContent does not allow body
if rw.Status != http.StatusNoContent {
t.Errorf("the status should be %d, got %d", http.StatusNoContent, rw.Status)
}
if len(rw.Body) != 0 {
t.Errorf("the length of the body should be 0, got %d", len(rw.Body))
t.Log(string(rw.Body))
}
}

0 comments on commit ec70f53

Please sign in to comment.