diff options
author | David Titarenco <david.titarenco@gmail.com> | 2009-11-13 18:06:47 -0800 |
---|---|---|
committer | David Titarenco <david.titarenco@gmail.com> | 2009-11-13 18:06:47 -0800 |
commit | 36d9192575ffcd0339bfaacedef536fe40d20ecb (patch) | |
tree | 7c4dcfce6d76cb65e14c22749eb542a59891cec4 | |
parent | 458d4d3ed90569d42aca90666d40277023af766d (diff) | |
download | golang-36d9192575ffcd0339bfaacedef536fe40d20ecb.tar.gz |
Created new Conn.Flush() public method so the fd pipeline can be drained arbitrarily by the user.
Commented both flush methods so people know what they are looking at.
This is a necessary fix for streaming and long polling HTTP services.
Fixes issue 93.
R=r, rsc, david.titarenco
http://codereview.appspot.com/154099
Committer: Russ Cox <rsc@golang.org>
-rw-r--r-- | src/pkg/http/server.go | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/pkg/http/server.go b/src/pkg/http/server.go index d4b23a20f..9178d5438 100644 --- a/src/pkg/http/server.go +++ b/src/pkg/http/server.go @@ -238,7 +238,7 @@ func errorKludge(c *Conn, req *Request) { } } -func (c *Conn) flush() { +func (c *Conn) finishRequest() { if !c.wroteHeader { c.WriteHeader(StatusOK) } @@ -251,6 +251,14 @@ func (c *Conn) flush() { c.buf.Flush(); } +// Flush sends any buffered data to the client. +func (c *Conn) Flush() { + if !c.wroteHeader { + c.WriteHeader(StatusOK) + } + c.buf.Flush(); +} + // Close the connection. func (c *Conn) close() { if c.buf != nil { @@ -277,7 +285,7 @@ func (c *Conn) serve() { if c.hijacked { return } - c.flush(); + c.finishRequest(); if c.closeAfterReply { break } |