From 2889332edfb90d70827fa714b0fa40a28b0621b5 Mon Sep 17 00:00:00 2001 From: LE Manh Cuong Date: Mon, 17 Dec 2018 11:06:30 +0700 Subject: [PATCH] net/http: make TimeoutHandler's ResponseWriter implement Pusher Fixes #29193 Change-Id: I03088205e51036abbc861ab5b7d141327b0429ae Reviewed-on: https://go-review.googlesource.com/c/154383 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/net/http/server.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/net/http/server.go b/src/net/http/server.go index e68ec2f01ef..9ae0bbff149 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -3223,6 +3223,25 @@ type timeoutWriter struct { code int } +var _ Pusher = (*timeoutWriter)(nil) +var _ Flusher = (*timeoutWriter)(nil) + +// Push implements the Pusher interface. +func (tw *timeoutWriter) Push(target string, opts *PushOptions) error { + if pusher, ok := tw.w.(Pusher); ok { + return pusher.Push(target, opts) + } + return ErrNotSupported +} + +// Flush implements the Flusher interface. +func (tw *timeoutWriter) Flush() { + f, ok := tw.w.(Flusher) + if ok { + f.Flush() + } +} + func (tw *timeoutWriter) Header() Header { return tw.h } func (tw *timeoutWriter) Write(p []byte) (int, error) {