How to have a non-blocking 'any' route, which proxies multiple method requests?

46 views
Skip to first unread message

Charlie Brady

unread,
Apr 11, 2015, 10:27:14 AM4/11/15
to mojol...@googlegroups.com

https://github.com/kraih/mojo/wiki/Blocking-vs-non-blocking-101

I see I can do this to have a non-blocking get handler:

...
$self->render_later;

$self->ua->get('http://www.superhugepage.com/blah.html' => sub {});
...

But I don't understand how to use Mojo::UserAgent in an 'any' handler,
where method might be 'get', 'put', 'delete', etc. Do I build a tx, attach
the callback to 'finish', then start it? Or just do:

$method = $self->req->method;
$self->ua->$method()

?

Thanks

Dan Book

unread,
Apr 11, 2015, 11:27:29 AM4/11/15
to mojol...@googlegroups.com
Perhaps this way:
my $tx = $ua->build_tx($method => ... normal get/post/etc args ...);
$ua->start($tx => sub {
  ...
});

Charlie Brady

unread,
Apr 11, 2015, 5:06:03 PM4/11/15
to mojol...@googlegroups.com

On Sat, 11 Apr 2015, Dan Book wrote:

> Perhaps this way:
> my $tx = $ua->build_tx($method => ... normal get/post/etc args ...);
> $ua->start($tx => sub {
> ...
> });

Thanks. I'll try that.

Next problem is what needs to be done to read the request body and
transfer it to the ua. Would that happen automatigically if the req is
cloned? In this case, would Mojo buffer the request? Does anyone have a
gist which proxies a request without reading and caching the request body?

I've found this which deals with some of these issues:

https://larig.wordpress.com/2012/08/01/a-mini-proxy-via-mojolicious/

Thanks all.

Jan Henning Thorsen

unread,
Apr 12, 2015, 8:22:38 AM4/12/15
to mojol...@googlegroups.com, charli...@budge.apana.org.au

Charlie Brady

unread,
Apr 12, 2015, 11:57:10 AM4/12/15
to Jan Henning Thorsen, mojol...@googlegroups.com

On Sun, 12 Apr 2015, Jan Henning Thorsen wrote:

> Are you building a proxy..? Maybe you want to have a look at either of
> these:
>
> https://metacpan.org/pod/Mojolicious::Plugin::Proxy

It looks to me that will proxy only get requests. It would be interesting
to see that extended for post, etc.

> https://github.com/mojoconf/MCT/blob/master/lib/MCT/Plugin/ACT.pm

I can't quite tell what that does, and the pod isn't helpful :-)
Reply all
Reply to author
Forward
0 new messages