Created
October 11, 2011 15:31
-
-
Save kraih/1278413 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 Mojolicious::Lite; | |
use Time::HiRes 'time'; | |
# How long did receiving the request take? | |
hook after_build_tx => sub { | |
my $tx = shift; | |
my $before = time; | |
$tx->req->on(finish => sub { | |
my $req = shift; | |
$req->headers->header('X-Time' => time - $before); | |
}); | |
}; | |
get '/' => sub { | |
my $self = shift; | |
my $time = $self->req->headers->header('X-Time'); | |
$self->render(text => "Receiving the request took exactly $time seconds."); | |
}; | |
app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment