<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Plack::Middleware::Head;
use strict;
use warnings;
use parent qw(Plack::Middleware);

sub call {
    my($self, $env) = @_;

    return $self-&gt;app-&gt;($env)
        unless $env-&gt;{REQUEST_METHOD} eq 'HEAD';

    $self-&gt;response_cb($self-&gt;app-&gt;($env), sub {
        my $res = shift;
        if ($res-&gt;[2]) {
            $res-&gt;[2] = [];
        } else {
            return sub {
                return defined $_[0] ? '': undef;
            };
        }
    });
}

1;

__END__

=head1 NAME

Plack::Middleware::Head - auto delete response body in HEAD requests

=head1 SYNOPSIS

  enable "Head";

=head1 DESCRIPTION

This middleware deletes response body in HEAD requests.

=head1 AUTHOR

Tatsuhiko Miyagawa

=head1 SEE ALSO

Rack::Head

=cut

</pre></body></html>