Skip to content

Instantly share code, notes, and snippets.

@kraih
Created October 11, 2011 15:31
Show Gist options
  • Save kraih/1278413 to your computer and use it in GitHub Desktop.
Save kraih/1278413 to your computer and use it in GitHub Desktop.
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