Plack::Middleware::Headers - modify HTTP response headers
version 0.11
use Plack::Builder; builder { enable 'Headers', set => ['X-Plack-One' => '1'], append => ['X-Plack-Two' => '2'], unset => ['X-Plack-Three']; enable 'Headers', code => '404', set => ['X-Robots-Tag' => 'noindex, noarchive, follow']; enable 'Headers', when => ['Content-Type' => qr{^text/}], set => ['Content-Type' => 'text/plain']; sub {['200', [], ['hello']]}; };
This Plack::Middleware simplifies creation (set or append), deletion (unset), and modification (set) of PSGI response headers. The modification can be enabled based on response code (code) or existing response headers(when). Use Plack::Middleware::Conditional to enable the middleware based in request headers.
set
append
unset
code
when
Overwrites existent header(s).
Remove existing header(s).
Add header(s).
Optional HTTP response code that modification of response headers is limited to.
Optional check on the response headers that must be true to actually modify headers. Either one provides a list of headers for which one of them must match. Matching can be tested against:
header => undef, # missing header header => $scalar # exact value header => /$regexp/ # regular expression
Alternatively one can check with a code reference that all response headers are passed to as list.
This module is an extened fork of Plack::Middleware::Header, originally created by Masahiro Chiba. Additional contributions by Wallace Reis.
Plack::Middleware, Plack::Builder
Jakob Voß
This software is copyright (c) 2014 by Jakob Voß.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Plack::Middleware::Headers, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::Middleware::Headers
CPAN shell
perl -MCPAN -e shell install Plack::Middleware::Headers
For more information on module installation, please visit the detailed CPAN module installation guide.