I've merged Scott Gifford's "Keep-Alive" patch with my own "HTTPS through a
proxy server", and applied them to libwww-perl-5.47.  The resulting diff is
attached.

I've included Scott's original e-mail that describes his changes.  My
change is simple:  saying 
GET 'https://some.site'
will now cause LWP to connect to the proxy server, issue a "CONNECT
some.site::443 HTTP/1.0" request, and then pass SSL messages through the
resulting connection.

 <<libwww-perl-5.47.patch>>  <<Persistent connections patch for
libwww-perl>> 

**********************************************************************
This e-mail is intended only for the addressee named above.
As this e-mail may contain confidential or privileged information,
if you are not the named addressee, you are not authorised to
retain, read, copy or disseminate this message or any part of it.
************************************************************************

libwww-perl-5.47.patch



Hello,

  I just finished patching up libwww-perl to handle persistent
connections, and thought I'd pop onto this list to post my patch and
make sure it works.  Apologies if this duplicates somebody else's
efforts; I just threw it together for a project, without checking if
anybody else was working on it.

  The patch adds a 'connection_cache' method to LWP::UserAgent, which
takes a boolean argument to turn connection caching on or off.  When
it is on, a connection cache is maintained as part of the UserAgent
object.  It is passed in to protocol handlers that support it (right
now just http), and they can access and modify the cache.  When it is
off, LWP behaves identically to before the patch.

  The bulk of the work is done in LWP::Protocol::http.  The
_new_socket method has been changed to check the cache first, and
store opened connections in the cache.  The request method has been
rearranged a little bit, to build all the headers and the request line
before connecting the socket.  This made it easier to wrap the whole
connect/send request/read response code inside a block and an eval, so
we can detect a cached connection we thought was open that wasn't, and
retry the whole thing if we need to.  If connection caching is
activated, we add a "Connection: Keep-Alive" header to our request,
and if we get the same back in our response, we look at the
Content-Length, and only read that may bytes before returning, leaving
the connection open.  We never explicitly close the socket now; we
rely on Perl to close it correctly when all references to it have
disappeared.  This makes managing the cached connections much simpler.

  This patch implements HTTP/1.0 style connection caching.  It works
correctly with or without proxies.  It never shuts connections down
for the lifetime of the UserAgent unless there is an error or the
server requests it; this could be considered a bug.

  Let me know if you have any problems with this patch.  I have tried
to make the changes as straightforward as possible, and as transparent
as possible if you don't turn on the connection_cache option.

-----ScottG.


libwww-perl-keepalive.patch



Reply via email to