From: Brad Fitzpatrick Date: Wed, 16 Mar 2011 21:32:35 +0000 (-0700) Subject: http: add NewProxyClientConn X-Git-Tag: weekly.2011-03-28~113 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a93f70c21ab47d0b014b190a0f779f4060565dca;p=gostls13.git http: add NewProxyClientConn This just returns a ClientConn suitable for writing proxy requests. To be used in Transport. R=rsc, petar-m CC=golang-dev https://golang.org/cl/4290052 --- diff --git a/src/pkg/http/persist.go b/src/pkg/http/persist.go index 53efd7c8c6..a8285c894a 100644 --- a/src/pkg/http/persist.go +++ b/src/pkg/http/persist.go @@ -211,7 +211,8 @@ type ClientConn struct { nread, nwritten int pipereq map[*Request]uint - pipe textproto.Pipeline + pipe textproto.Pipeline + writeReq func(*Request, io.Writer) os.Error } // NewClientConn returns a new ClientConn reading and writing c. If r is not @@ -220,7 +221,20 @@ func NewClientConn(c net.Conn, r *bufio.Reader) *ClientConn { if r == nil { r = bufio.NewReader(c) } - return &ClientConn{c: c, r: r, pipereq: make(map[*Request]uint)} + return &ClientConn{ + c: c, + r: r, + pipereq: make(map[*Request]uint), + writeReq: (*Request).Write, + } +} + +// NewProxyClientConn works like NewClientConn but writes Requests +// using Request's WriteProxy method. +func NewProxyClientConn(c net.Conn, r *bufio.Reader) *ClientConn { + cc := NewClientConn(c, r) + cc.writeReq = (*Request).WriteProxy + return cc } // Close detaches the ClientConn and returns the underlying connection as well @@ -281,7 +295,7 @@ func (cc *ClientConn) Write(req *Request) (err os.Error) { } cc.lk.Unlock() - err = req.Write(c) + err = cc.writeReq(req, c) cc.lk.Lock() defer cc.lk.Unlock() if err != nil {