Add ability to unwrap statusCodeTracker to get inner http.ResponseWriter
mpuncel opened this issue · 2 comments
Existing HTTP handler code that needs to get at the underlying http.Flusher (or http.Hijacker etc) interfaces from the http.ResponseWriter breaks when the Middleware
is installed.
One complex approach to address this would be to do something similar to https://github.com/DataDog/dd-trace-go/blob/v1/contrib/internal/httputil/trace_gen.go#L18.
A more simple approach would be to add something like
+func (w *statusCodeTracker) InnerResponseWriter() http.ResponseWriter {
+ return w.ResponseWriter
+}
+
+type ResponseWriterWrapper interface {
+ InnerResponseWriter() http.ResponseWriter
+}
The existing code can then be modified to first try to cast to a nethttp.ResponseWriterWrapper
, unwrap it if it works, and then get the underlying http.Flusher
etc. from that. I'll submit a patch using this approach and we can discuss from there.
I believe this is addressed by #26, closing. Feel free to reopen if not.
that approach is better than my initial suggestion and solves my use case, thanks for merging that!