Perl - Force LWP::Protocol subclass selection, or is there a better way?

197 views Asked by At

Background:

I've written an LWP::Protocol "implementor" for HTTP(S) based on AnyEvent::HTTP. (i.e: it implements both HTTP and HTTPS).

It's different than LWP::Protocol::AnyEvent::http or Coro::LWP in that it doesn't BLOCK on $protocol->request. I've implemented most of the same hacks for select(), name-resolution etc that Coro::LWP does, but making better use of AnyEvent.

The HTTP response returned by $protocol->request() is 230 - Pending Completion of Request for now but I'm open to better ways to convey that it isn't a completed request.

I've also written a subclass of HTTP::Response which forces BLOCKING on the standard "consumer" methods if they attempt to use parts of the response before it's complete; it also adds methods for working nicely with internal/provided AnyEvent::CondVar so that you can fire lots of requests off at once, as well as do other stuff with AnyEvent. (I've also overridden all of LWP::UserAgent's post-send_request() logic to defer it until the real request completion).

Problem:

I'm currently doing a hack were I have my LWP::UserAgent subclass "upgrade" the URL scheme by appending '_async' for async requests, and I've got the LWP::Protocol subclass being an "implementor" for schemes matching /^https?_async$/

Question:

How can I get my LWP::UserAgent subclass to choose my (more asynchronous) HTTP & HTTPS protocol "implementors" instead of others installed on the system? (i.e: when the LWP::UserAgent subclass calls LWP::Protocol::create).

Can I force selection of my "implementors"? Or is there a more natural way to do this?

1

There are 1 answers

13
Noam Rathaus On BEST ANSWER

You need to call implementor in close proximity to your send_request call:

LWP::Protocol::implementor('http', 'your::module::name');

See source of http://search.cpan.org/~gaas/LWP-Protocol-http10-6.03/lib/LWP/Protocol/http10.pm to understand what you need to implement to replace the HTTP protocol handler