Skip to content

Instantly share code, notes, and snippets.

@shelling
Created July 27, 2012 04:20
Show Gist options
  • Select an option

  • Save shelling/3186157 to your computer and use it in GitHub Desktop.

Select an option

Save shelling/3186157 to your computer and use it in GitHub Desktop.
#!/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