Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Dancer2 doesn't play well with LWP::Protocol::PSGI and/or apphandler => 'PSGI' doesn't kick in #447

Closed
gideondsouza opened this Issue · 7 comments

3 participants

@gideondsouza

The following example from the LWP::Protocol::PSGI POD, works with Dancer but not with Dancer2.

use LWP::UserAgent;
use LWP::Protocol::PSGI;

my $psgi_app = do {
    use Dancer;#ATTN : Change this to Dancer2 and the app hangs before this line
    setting apphandler => 'PSGI';
    get '/search' => sub {
        return 'googling ' . params->{q};
    };
    dance;
};
# Register the $psgi_app to handle all LWP requests
LWP::Protocol::PSGI->register($psgi_app); 
my $ua  = LWP::UserAgent->new;
my $res = $ua->get("http://www.google.com/search?q=bar");
print $res->content; # "googling bar"

So the above sample would hang when Dancer2 was used.

With some timely help from @mst-shadowcat turns out, if I add this : BEGIN { $ENV{DANCER_APPHANDLER} = 'PSGI';}, the second use statement, it works ok.

Not sure if it's just the following not kicking in

apphandler => 'PSGI' 

or something else.

@ambs
Owner

This can be (didn't look into the code yet):

  • Setting being ignored, or more likely,
  • The usual problems with sets and triggers not working.
@gideondsouza

I don't understand what triggers are here? Could someone explain s'il vous plait.

@ambs
Owner

@gideondsouza, atm just forget them. With the latest patch from @veryrusty you can use use Dancer apphandler=>"PSGI" and this issue can gets closed :dancers:

@gideondsouza

Alright :smile: I racked my brains a little generally about setting() and set() not working while doing command line options, couldn't figure it out too well. I thought this had something to do with it.

@xsawyerx
Owner

This is because set $key => $value changes applications, not the runner, where the the decision on which web server to run it under is done.

@xsawyerx
Owner

Fixed it locally. Setting up a test and pushing.

@xsawyerx xsawyerx referenced this issue from a commit
@xsawyerx xsawyerx Make apphandler a global variable:
Recently when running

    set apphandler => 'PSGI'

it did not pick up because setting the apphandler affected only
the Dancer App, while the apphandler was (correctly) decided and
used by the Dancer Runner.

By making the "apphandler" option a global trigger that updates the
Dancer Runner object, this will now work.

Added a test that uses LWP::Protocol::PSGI, which exposed this
problem in GH #447.
22523a3
@xsawyerx
Owner

Closed by 22523a3.

@xsawyerx xsawyerx closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.