Created
November 10, 2011 14:53
-
-
Save bduggan/1355027 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 | |
# 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