aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Catalyst/Plugin/Compress/Gzip.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2017-08-29 09:33:20 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2017-08-29 16:17:34 +0100
commit68111f484bf27f03ce023497fdc5868c2b724ffb (patch)
treef8ffd8de32b1fce7925ee9759d6c808e8bcf3aca /perllib/Catalyst/Plugin/Compress/Gzip.pm
parent66bd45b66911860dd2d59e5a6e38586a1641a2d7 (diff)
Add debug toolbar middleware.
If debug is enabled, using the CATALYST_DEBUG/FIXMYSTREET_APP_DEBUG environment variables, add a debug toolbar to the output, including request/response details and a database query log. This uses Plack middleware, so works by switching our dev server to use Starman with plack directly, rather than via the script runner. We remove the GZip compression as this interferes, and take a local copy of the QueryLog::AdoptPlack trait as it needs a tweak to work. Make sure the CSP header is not output in debug mode, as that would prevent the toolbar JavaScript from running.
Diffstat (limited to 'perllib/Catalyst/Plugin/Compress/Gzip.pm')
-rw-r--r--perllib/Catalyst/Plugin/Compress/Gzip.pm82
1 files changed, 0 insertions, 82 deletions
diff --git a/perllib/Catalyst/Plugin/Compress/Gzip.pm b/perllib/Catalyst/Plugin/Compress/Gzip.pm
deleted file mode 100644
index 06532c84c..000000000
--- a/perllib/Catalyst/Plugin/Compress/Gzip.pm
+++ /dev/null
@@ -1,82 +0,0 @@
-package Catalyst::Plugin::Compress::Gzip;
-use strict;
-use warnings;
-use MRO::Compat;
-
-use Compress::Zlib ();
-
-sub finalize_headers {
- my $c = shift;
-
- if ( $c->response->content_encoding ) {
- return $c->next::method(@_);
- }
-
- unless ( $c->response->body ) {
- return $c->next::method(@_);
- }
-
- unless ( $c->response->status == 200 ) {
- return $c->next::method(@_);
- }
-
- unless ( $c->response->content_type =~ /^text|xml$|javascript$/ ) {
- return $c->next::method(@_);
- }
-
- my $accept = $c->request->header('Accept-Encoding') || '';
-
- unless ( index( $accept, "gzip" ) >= 0 ) {
- return $c->next::method(@_);
- }
-
-
- my $body = $c->response->body;
- eval { local $/; $body = <$body> } if ref $body;
- die "Response body is an unsupported kind of reference" if ref $body;
-
- $c->response->body( Compress::Zlib::memGzip( $body ) );
- $c->response->content_length( length( $c->response->body ) );
- $c->response->content_encoding('gzip');
- $c->response->headers->push_header( 'Vary', 'Accept-Encoding' );
-
- $c->next::method(@_);
-}
-
-1;
-
-__END__
-
-=head1 NAME
-
-Catalyst::Plugin::Compress::Gzip - Gzip response
-
-=head1 SYNOPSIS
-
- use Catalyst qw[Compress::Gzip];
-
-
-=head1 DESCRIPTION
-
-Gzip compress response if client supports it. Changed from CPAN version to
-overload finalize_headers, rather than finalize.
-
-=head1 METHODS
-
-=head2 finalize_headers
-
-=head1 SEE ALSO
-
-L<Catalyst>.
-
-=head1 AUTHOR
-
-Christian Hansen, C<ch@ngmedia.com>
-Matthew Somerville.
-
-=head1 LICENSE
-
-This library is free software . You can redistribute it and/or modify it under
-the same terms as perl itself.
-
-=cut