While maintaining my Go spaserve <https://github.com/thediveo/spaserve> 
module for serving single-page applications with client-side DOM routing 
and on different routes simultaneously I noticed different logging behavior 
between http.timeoutWriter.WriteHeader 
<https://cs.opensource.google/go/go/+/master:src/net/http/server.go;drc=457fd1d52d17fc8e73d4890150eadab3128de64d;l=3478>
 
and httptest.ResponseRecorder.WriteHeader 
<https://cs.opensource.google/go/go/+/master:src/net/http/httptest/recorder.go;drc=ff14e844d26090e09aa335d836f737c09a7a0402;l=143>
.

While the "production" response writer explicitly logs and thus warns of 
superfluous WriteHeader calls, the testing response recorder doesn't and 
stays silent. I would have expected that an httptest response recorder 
would at least also log any superfluous calls, or better, somehow report 
such superfluous calls in a way that tests can check and fail where 
necessary.

Would it make sense to create a feature request issue for httptest?

What would be a good design to make httptest detect and preferably 
immediately report superfluous calls to WriteHeader in order immediately 
detect the "offending" call site? I recon that calling panic would be 
rather rude. Would an additional (new) "SuperfluousWriteHeader func()" 
struct field in ResponseRecorder be an acceptable proposal? 
SuperfluousWriteHeader would be called if non-nil and would be used by 
tests to wire into their particular testing harness.

Other ideas and suggestions?

Note bene: at the moment, I'm wrapping httptest's ResponseRecorder in my 
own WrappedResponseRecorder 
<https://github.com/thediveo/spaserve/blob/0ce0b260904d187f0dda2989bac2cafee228ad34/test/httptest/recorder.go#L30>.
 
Maybe there's a better way to do this?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/61c0dd07-e6d1-4008-936c-9a4c25be2fd2n%40googlegroups.com.

Reply via email to