diff options
Diffstat (limited to 'libgo/go/http/persist.go')
-rw-r--r-- | libgo/go/http/persist.go | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/libgo/go/http/persist.go b/libgo/go/http/persist.go index e4eea68..78bf905 100644 --- a/libgo/go/http/persist.go +++ b/libgo/go/http/persist.go @@ -24,6 +24,9 @@ var ( // to regain control over the connection. ServerConn supports pipe-lining, // i.e. requests can be read out of sync (but in the same order) while the // respective responses are sent. +// +// ServerConn is low-level and should not be needed by most applications. +// See Server. type ServerConn struct { lk sync.Mutex // read-write protects the following fields c net.Conn @@ -111,7 +114,7 @@ func (sc *ServerConn) Read() (req *Request, err os.Error) { // Make sure body is fully consumed, even if user does not call body.Close if lastbody != nil { // body.Close is assumed to be idempotent and multiple calls to - // it should return the error that its first invokation + // it should return the error that its first invocation // returned. err = lastbody.Close() if err != nil { @@ -211,6 +214,9 @@ func (sc *ServerConn) Write(req *Request, resp *Response) os.Error { // connection, while respecting the HTTP keepalive logic. ClientConn // supports hijacking the connection calling Hijack to // regain control of the underlying net.Conn and deal with it as desired. +// +// ClientConn is low-level and should not be needed by most applications. +// See Client. type ClientConn struct { lk sync.Mutex // read-write protects the following fields c net.Conn @@ -222,7 +228,6 @@ type ClientConn struct { pipe textproto.Pipeline writeReq func(*Request, io.Writer) os.Error - readRes func(buf *bufio.Reader, method string) (*Response, os.Error) } // NewClientConn returns a new ClientConn reading and writing c. If r is not @@ -236,7 +241,6 @@ func NewClientConn(c net.Conn, r *bufio.Reader) *ClientConn { r: r, pipereq: make(map[*Request]uint), writeReq: (*Request).Write, - readRes: ReadResponse, } } @@ -339,8 +343,13 @@ func (cc *ClientConn) Pending() int { // returned together with an ErrPersistEOF, which means that the remote // requested that this be the last request serviced. Read can be called // concurrently with Write, but not with another Read. -func (cc *ClientConn) Read(req *Request) (resp *Response, err os.Error) { +func (cc *ClientConn) Read(req *Request) (*Response, os.Error) { + return cc.readUsing(req, ReadResponse) +} +// readUsing is the implementation of Read with a replaceable +// ReadResponse-like function, used by the Transport. +func (cc *ClientConn) readUsing(req *Request, readRes func(*bufio.Reader, *Request) (*Response, os.Error)) (resp *Response, err os.Error) { // Retrieve the pipeline ID of this request/response pair cc.lk.Lock() id, ok := cc.pipereq[req] @@ -383,7 +392,7 @@ func (cc *ClientConn) Read(req *Request) (resp *Response, err os.Error) { } } - resp, err = cc.readRes(r, req.Method) + resp, err = readRes(r, req) cc.lk.Lock() defer cc.lk.Unlock() if err != nil { |