Created
July 27, 2012 04:20
-
-
Save shelling/3186157 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
| #!/usr/bin/env perl | |
| use Modern::Perl; | |
| use Plack; | |
| use MogileFS::Client; | |
| my $client = MogileFS::Client->new( domain => "test", hosts => ["localhost:7001"] ); | |
| use HTTP::Request; | |
| use LWP::UserAgent; | |
| my $agent = LWP::UserAgent->new; | |
| use MIME::Types; | |
| my $mime = MIME::Types->new; | |
| my $app = sub { | |
| my $env = shift; | |
| my $url = $env->{REQUEST_URI}; | |
| my $req = HTTP::Request->new(GET => $client->get_paths($url)); | |
| return sub { | |
| my $respond = shift; | |
| my $w = $respond->([ | |
| 200, | |
| [ | |
| "Content-Type" => $mime->mimeTypeOf($url), | |
| "Content-Length" => $client->file_info($url)->{length}, | |
| ] | |
| ]); | |
| $agent->request($req, sub { | |
| my ($chunk, $res) = @_; | |
| $w->write($chunk); | |
| }); | |
| $w->close; | |
| }; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment