Plack::Middleware::Runtime - Sets an X-Runtime response header


Plack documentation Contained in the Plack distribution.

Index


Code Index:

NAME

Top

Plack::Middleware::Runtime - Sets an X-Runtime response header

SYNOPSIS

Top

  enable "Runtime";

DESCRIPTION

Top

Plack::Middleware::Runtime is a Plack middleware component that sets application's response time, in seconds to X-Runtime HTTP response header.

OPTIONS

Top

header_name

Name of the header. Defaults to X-Runtime.

AUTHOR

Top

Tatsuhiko Miyagawa

SEE ALSO

Top

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__