only allow writing a response body for status codes that allow bodies

fixes #386
This commit is contained in:
Marten Seemann
2017-01-07 09:49:22 +07:00
parent 563c56fa74
commit 53d2290a59
2 changed files with 28 additions and 0 deletions

View File

@@ -92,4 +92,12 @@ var _ = Describe("Response Writer", func() {
w.WriteHeader(500)
Expect(headerStream.Bytes()).To(Equal([]byte{0x0, 0x0, 0x1, 0x1, 0x4, 0x0, 0x0, 0x0, 0x5, 0x88})) // 0x88 is 200
})
It("doesn't allow writes if the status code doesn't allow a body", func() {
w.WriteHeader(304)
n, err := w.Write([]byte("foobar"))
Expect(n).To(BeZero())
Expect(err).To(MatchError(http.ErrBodyNotAllowed))
Expect(dataStream.Bytes()).To(HaveLen(0))
})
})