downsides of wrapping ResponseWriter

Jun 20, 2022

tl;dr: ResponseWriter's optional interfaces spoil the fun, when you try to compose it in this (or any) way.

The issue is, that the wrapping type now hides all the optional interfaces, ResponseWriter supports (namely Flusher, Pusher, Hijacker and CloseNotifier.

Even if the embedded ResponseWriter implements them, the type statusRecorder won't; it will only have the methods that are explicitly declared for it, plus the ones from embedded interfaces, that are known at compile time.

I hadn't considered the downisdes of wrapping ResponseWriter (which I've always done immediately) before.

Particularly, losing Flusher means losing the ability to write chunked responses which is The Weirdly Obscure Art of Streamed HTML

↑ up