Last active
March 7, 2017 19:46
-
-
Save perlpilot/b943b022c67c8289c2464444f9c0d02b to your computer and use it in GitHub Desktop.
Weird interaction between LWP::UserAgent and Dancer2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ plackup bin/app.psgi | |
HTTP::Server::PSGI: Accepting connections at http://0:5000/ | |
[MyApp:4077] core @2017-03-07 13:40:39> looking for get /code in /local/bin/unified-app-0.1/perl/lib/site_perl/5.16.3/Dancer2/Core/App.pm l. 1180 | |
[MyApp:4077] core @2017-03-07 13:40:39> Entering hook core.app.before_request in (eval 133) l. 1 | |
[MyApp:4077] core @2017-03-07 13:40:39> Entering hook core.app.after_request in (eval 133) l. 1 | |
127.0.0.1 - - [07/Mar/2017:13:40:39 -0600] "GET /code HTTP/1.1" 200 15 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2" | |
[MyApp:4077] core @2017-03-07 13:40:42> looking for get /status in /local/bin/unified-app-0.1/perl/lib/site_perl/5.16.3/Dancer2/Core/App.pm l. 1180 | |
[MyApp:4077] core @2017-03-07 13:40:42> Entering hook core.app.before_request in (eval 133) l. 1 | |
[MyApp:4077] core @2017-03-07 13:40:47> Entering hook core.app.after_request in (eval 133) l. 1 | |
127.0.0.1 - - [07/Mar/2017:13:40:47 -0600] "GET /status HTTP/1.1" 200 769 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2" | |
[MyApp:4077] core @2017-03-07 13:40:47> looking for get /code in /local/bin/unified-app-0.1/perl/lib/site_perl/5.16.3/Dancer2/Core/App.pm l. 1180 | |
[MyApp:4077] core @2017-03-07 13:40:47> Entering hook core.app.before_request in (eval 133) l. 1 | |
[MyApp:4077] core @2017-03-07 13:40:47> Entering hook core.app.after_request in (eval 133) l. 1 | |
127.0.0.1 - - [07/Mar/2017:13:40:47 -0600] "GET /code HTTP/1.1" 200 15 "-" "libwww-perl/6.15" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat lib/MyApp.pm | |
package MyApp; | |
use Dancer2; | |
use LWP::UserAgent; | |
use Data::Dumper::Concise; | |
our $VERSION = '0.1'; | |
get '/code' => sub { | |
return "BLAH " . time . "\n"; | |
}; | |
get '/status' => sub { | |
my $ua = LWP::UserAgent->new; | |
$ua->timeout(5); | |
my $url = uri_for('/code'); | |
my $response = $ua->get($url); | |
my $body; | |
if ($response->is_success) { | |
$body .= "yay!"; | |
} else { | |
$body .= "FAILED to get: " . $response->status_line; | |
} | |
$body .= Dumper($response); | |
header 'Content-Type' => 'text/plain'; | |
return $body; | |
}; | |
true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ curl http://localhost:5000/code | |
BLAH 148891563 | |
$ curl http://localhost:5000/status | |
FAILED to get: 500 read timeoutbless( { | |
_content => "read timeout at /local/bin/unified-app-0.1/perl/lib/site_perl/5.16.3/Net/HTTP/Methods.pm line 271.\n", | |
_headers => bless( { | |
"::std_case" => { | |
"client-date" => "Client-Date", | |
"client-warning" => "Client-Warning" | |
}, | |
"client-date" => "Tue, 07 Mar 2017 19:40:47 GMT", | |
"client-warning" => "Internal response", | |
"content-type" => "text/plain" | |
}, 'HTTP::Headers' ), | |
_msg => "read timeout", | |
_rc => 500, | |
_request => bless( { | |
_content => "", | |
_headers => bless( { | |
"user-agent" => "libwww-perl/6.15" | |
}, 'HTTP::Headers' ), | |
_method => "GET", | |
_uri => bless( do{\(my $o = "http://localhost:5000/code")}, 'URI::http' ) | |
}, 'HTTP::Request' ) | |
}, 'HTTP::Response' ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment