Last active
December 11, 2015 18:29
-
-
Save hisaichi5518/4642192 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| use strict; | |
| use warnings; | |
| use utf8; | |
| use Plack::Util; | |
| use Encode; | |
| use AnyEvent; | |
| use AnyEvent::HTTP (); | |
| $AnyEvent::HTTP::MAX_PER_HOST = 20; | |
| my $url = 'http://localhost:5000/'; | |
| my $app = sub { | |
| my $env = shift; | |
| my $cv = AE::cv; | |
| AnyEvent::HTTP::http_get $url, sub { | |
| my $content = decode_utf8(shift); | |
| $cv->send( | |
| [ 200, [ "Content-Type" => 'text/plain', ], ["あいうえお: $content"] ] ); | |
| }; | |
| my $res = sub { | |
| my $start_response = shift; | |
| $cv->cb( | |
| sub { | |
| $start_response->( shift->recv ); | |
| } | |
| ); | |
| }; | |
| Plack::Util::response_cb($res, sub { | |
| sub { | |
| my $chunk = shift; | |
| return unless defined $chunk; | |
| return Encode::encode_utf8($chunk) if Encode::is_utf8($chunk); | |
| return $chunk; | |
| } | |
| }); | |
| }; | |
| # http://blog.nomadscafe.jp/2009/10/psgiplack-web-server.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment