@@ -, +, @@ pages directly under Plack/PSGI --- C4/Context.pm | 34 ++++++++++++++++++++++++++++++++++ errors/400.pl | 2 +- errors/401.pl | 2 +- errors/402.pl | 2 +- errors/403.pl | 2 +- errors/404.pl | 2 +- errors/500.pl | 2 +- opac/errors/400.pl | 2 +- opac/errors/401.pl | 2 +- opac/errors/402.pl | 2 +- opac/errors/403.pl | 2 +- opac/errors/404.pl | 2 +- opac/errors/500.pl | 2 +- 13 files changed, 46 insertions(+), 12 deletions(-) --- a/C4/Context.pm +++ a/C4/Context.pm @@ -42,6 +42,7 @@ use File::Spec; use POSIX; use YAML::XS; use ZOOM; +use List::MoreUtils qw(any); use Koha::Caches; use Koha::Config::SysPref; @@ -978,6 +979,39 @@ sub needs_install { return ($self->preference('Version')) ? 0 : 1; } +=head3 is_psgi_or_plack + +is_psgi_or_plack returns true if there is an environmental variable +prefixed with "psgi" or "plack". This is useful for detecting whether +this is a PSGI app or a CGI app, and implementing code as appropriate. + +=cut + +sub is_psgi_or_plack { + my $is_psgi_or_plack = 0; + if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { + $is_psgi_or_plack = 1; + } + return $is_psgi_or_plack; +} + +=head3 is_internal_PSGI_request + +is_internal_PSGI_request is used to detect if this request was made +from within the individual PSGI app or externally from the mounted PSGI +app + +=cut + +#NOTE: This is not a very robust method but it's the best we have so far +sub is_internal_PSGI_request { + my $is_internal = 0; + if ( (__PACKAGE__->is_psgi_or_plack) && ( $ENV{REQUEST_URI} !~ /^(\/intranet|\/opac)/ ) ){ + $is_internal = 1; + } + return $is_internal; +} + __END__ =head1 ENVIRONMENT --- a/errors/400.pl +++ a/errors/400.pl @@ -38,7 +38,7 @@ $template->param ( errno => 400, ); my $status = '400 Bad Request'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Context->is_internal_PSGI_request() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/errors/401.pl +++ a/errors/401.pl @@ -37,7 +37,7 @@ $template->param ( errno => 401, ); my $status = '401 Unauthorized'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Context->is_internal_PSGI_request() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/errors/402.pl +++ a/errors/402.pl @@ -38,7 +38,7 @@ $template->param ( errno => 402, ); my $status = '402 Payment Required'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Context->is_internal_PSGI_request() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/errors/403.pl +++ a/errors/403.pl @@ -38,7 +38,7 @@ $template->param ( errno => 403, ); my $status = '403 Forbidden'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Context->is_internal_PSGI_request() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/errors/404.pl +++ a/errors/404.pl @@ -38,7 +38,7 @@ $template->param ( errno => 404, ); my $status = '404 Not Found'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Context->is_internal_PSGI_request() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/errors/500.pl +++ a/errors/500.pl @@ -38,7 +38,7 @@ $template->param ( errno => 500, ); my $status = '500 Internal Server Error'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Context->is_internal_PSGI_request() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/opac/errors/400.pl +++ a/opac/errors/400.pl @@ -38,7 +38,7 @@ $template->param ( errno => 400, ); my $status = '400 Bad Request'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Context->is_internal_PSGI_request() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/opac/errors/401.pl +++ a/opac/errors/401.pl @@ -38,7 +38,7 @@ $template->param ( errno => 401, ); my $status = '401 Unauthorized'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Context->is_internal_PSGI_request() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/opac/errors/402.pl +++ a/opac/errors/402.pl @@ -38,7 +38,7 @@ $template->param ( errno => 402, ); my $status = '402 Payment Required'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Context->is_internal_PSGI_request() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/opac/errors/403.pl +++ a/opac/errors/403.pl @@ -38,7 +38,7 @@ $template->param ( errno => 403, ); my $status = '403 Forbidden'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Context->is_internal_PSGI_request() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/opac/errors/404.pl +++ a/opac/errors/404.pl @@ -38,7 +38,7 @@ $template->param ( errno => 404, ); my $status = '404 Not Found'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Context->is_internal_PSGI_request() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; --- a/opac/errors/500.pl +++ a/opac/errors/500.pl @@ -38,7 +38,7 @@ $template->param ( errno => 500, ); my $status = '500 Internal Server Error'; -if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { +if ( C4::Context->is_internal_PSGI_request() ) { $status = '200 OK'; } output_with_http_headers $query, $cookie, $template->output, 'html', $status; --