http://golang.org/pkg/http/#Flusher says ResponseWriter implements the Flusher interface

1,292 views
Skip to first unread message

CrossWall

unread,
Jul 3, 2011, 12:57:14 AM7/3/11
to golan...@googlegroups.com
But I can't do rw.Flush() on a http.ResponseWriter

David Symonds

unread,
Jul 3, 2011, 1:05:50 AM7/3/11
to golan...@googlegroups.com
On Sun, Jul 3, 2011 at 2:57 PM, CrossWall <tiantia...@gmail.com> wrote:

> But I can't do rw.Flush() on a http.ResponseWriter

Your subject line says "http://golang.org/pkg/http/#Flusher says
ResponseWriter implements the Flusher interface", but that's not true.
It says
"The Flusher interface is implemented by ResponseWriters that allow
an HTTP handler to flush buffered data to the client."

That is, among the set of things implementing ResponseWriter there are
some that also implement the Flusher interface, and those are ones
allow HTTP handlers to flush buffered data. Keep in mind that both
ResponseWriter and Flusher are interfaces, not concrete types.

You might want to read
http://golang.org/doc/effective_go.html#interfaces_and_types
to get a better feel for the relationship between interface and concrete types.


Dave.

Jessta

unread,
Jul 3, 2011, 1:05:58 AM7/3/11
to golan...@googlegroups.com
On Sun, Jul 3, 2011 at 2:57 PM, CrossWall <tiantia...@gmail.com> wrote:
> But I can't do rw.Flush() on a http.ResponseWriter

Look again,


"The Flusher interface is implemented by ResponseWriters that allow an
HTTP handler to flush buffered data to the client."

ResponseWriter is an interface. It's saying that if a ResponseWriter
that someone writes has a Flush() methods then the http package code
will use that method.
It doesn't appear that any of the ResponseWriters in the http pkg
satisfy the Flusher interface. But third-party code might.

- jessta


--
=====================
http://jessta.id.au

andrey mirtchovski

unread,
Jul 3, 2011, 1:10:01 AM7/3/11
to Jessta, golan...@googlegroups.com
the testing code in client_test.go uses the following cast:

w.(Flusher).Flush()

Islan Dberry

unread,
Jul 3, 2011, 1:36:30 AM7/3/11
to golan...@googlegroups.com
Use the following code to flush an http response where w is an http.ResponseWriter:

if f, ok := w.(http.Flusher); ok {
   f.Flush()
} else {
   // Response writer does not support flush.
}

The http.ResponseWriter implemented by the standard http package supports flush.  The AppEngine http.ResponseWriter does not support flush.

CrossWall

unread,
Jul 3, 2011, 1:44:15 AM7/3/11
to golan...@googlegroups.com
In fact what I'm saying is the standard http package's ResponseWriter.
Reply all
Reply to author
Forward
0 new messages