Skip to content

Instantly share code, notes, and snippets.

@bduggan
Created November 10, 2011 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bduggan/1355027 to your computer and use it in GitHub Desktop.
Save bduggan/1355027 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
# put.pl
# This works :
# ./put.pl daemon
# mojo get --method PUT --content 'foo' --header 'X-Disk: /tmp' http://localhost:3000/here
# This does not :
# ./put.pl get --method PUT --content 'foo' --header 'X-Disk: /tmp' /here
# This prints "after_build_tx" in the log, unlike --method PUT
# ./put.pl get /
use Mojolicious::Lite;
$ENV{MOJO_MAX_MEMORY_SIZE} = 2; # Force temp files.
$ENV{MOJO_TMPDIR} = "/nosuchdir"; # test setting tempdir dynamically
app->hook(
after_build_tx => sub {
my ( $tx, $app ) = @_;
app->log->warn("after_build_tx");
$tx->req->content->on( body => sub {
my $content = shift;
my $disk = $content->headers->header('X-Disk');
$content->asset->on(
upgrade => sub {
my ( $mem, $file ) = @_;
$file->tmpdir($disk);
}
);
})
}
);
get '/' => sub {
shift->render_text('hi');
};
put '/here' => sub {
shift->render_text('ok');
};
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment