| Plack documentation | Contained in the Plack distribution. |
Plack::Middleware::Runtime - Sets an X-Runtime response header
enable "Runtime";
Plack::Middleware::Runtime is a Plack middleware component that sets application's response time, in seconds to X-Runtime HTTP response header.
Name of the header. Defaults to X-Runtime.
Tatsuhiko Miyagawa
Time::HiRes Rack::Runtime
| Plack documentation | Contained in the Plack distribution. |
package Plack::Middleware::Runtime; use strict; use parent qw(Plack::Middleware); use Plack::Util; use Plack::Util::Accessor qw(header_name); use Time::HiRes; sub call { my($self, $env) = @_; my $start = [ Time::HiRes::gettimeofday ]; my $res = $self->app->($env); $self->response_cb($res, sub { my $res = shift; my $req_time = sprintf '%.6f', Time::HiRes::tv_interval($start); Plack::Util::header_set($res->[1], 'X-Runtime', $req_time); }); } 1; __END__