[Python-Dev] new httplib?

Greg Stein gstein@lyra.org
Thu, 17 Feb 2000 11:40:46 -0800 (PST)


On Thu, 17 Feb 2000, Jeremy Hylton wrote:
>...
> The one thing I don't see how to do with the new code is pipeline
> requests.  Is that possible?  It's not a big deal if pipelining isn't
> support, since the current implementation doesn't support it at all.

Pipelining is very important... it is once of the big advances in HTTP/1.1
(well, the advance is really the "chunked" transfer encoding which
*allows* pipelining to occur more often).

To do pipelining, just keep feeding requests into the thing:

-------------------------
conn = httplib.HTTPConnection('www.python.org')

conn.request('GET', '/')
code, msg, response = conn.getreply()
print response.read()

conn.request('GET', '/sigs/')
code, msg, response = conn.getreply()
print response.read()
-------------------------

Note that the code requires you to consume the response before issuing
another request (it will raise an error otherwise).

The connection object will connect automatically connect to the host. It
will keep the connection open per HTTP/1.1 guidelines (or close it when
told to). If an "broken pipe" occurs during the sending of the request
(the other end closed the socket), then it will close, reconnect, and
re-issue the request (just once). The broken pipe typically occurs if you
wait too long between requests. The client can force a connect or a close
thru the connection object API.

In addition to the simple request() method above, there is the standard
putrequest, putheader, endheader style.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/