View | Details | Raw Unified | Return to bug 29420
Collapse All | Expand All

(-)a/C4/Context.pm (+34 lines)
Lines 42-47 use File::Spec; Link Here
42
use POSIX;
42
use POSIX;
43
use YAML::XS;
43
use YAML::XS;
44
use ZOOM;
44
use ZOOM;
45
use List::MoreUtils qw(any);
45
46
46
use Koha::Caches;
47
use Koha::Caches;
47
use Koha::Config::SysPref;
48
use Koha::Config::SysPref;
Lines 978-983 sub needs_install { Link Here
978
    return ($self->preference('Version')) ? 0 : 1;
979
    return ($self->preference('Version')) ? 0 : 1;
979
}
980
}
980
981
982
=head3 is_psgi_or_plack
983
984
is_psgi_or_plack returns true if there is an environmental variable
985
prefixed with "psgi" or "plack". This is useful for detecting whether
986
this is a PSGI app or a CGI app, and implementing code as appropriate.
987
988
=cut
989
990
sub is_psgi_or_plack {
991
    my $is_psgi_or_plack = 0;
992
    if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
993
        $is_psgi_or_plack = 1;
994
    }
995
    return $is_psgi_or_plack;
996
}
997
998
=head3 is_internal_PSGI_request
999
1000
is_internal_PSGI_request is used to detect if this request was made
1001
from within the individual PSGI app or externally from the mounted PSGI
1002
app
1003
1004
=cut
1005
1006
#NOTE: This is not a very robust method but it's the best we have so far
1007
sub is_internal_PSGI_request {
1008
    my $is_internal = 0;
1009
    if ( (__PACKAGE__->is_psgi_or_plack) && ( $ENV{REQUEST_URI} !~ /^(\/intranet|\/opac)/ ) ){
1010
        $is_internal = 1;
1011
    }
1012
    return $is_internal;
1013
}
1014
981
__END__
1015
__END__
982
1016
983
=head1 ENVIRONMENT
1017
=head1 ENVIRONMENT
(-)a/errors/400.pl (-1 / +1 lines)
Lines 38-44 $template->param ( Link Here
38
    errno => 400,
38
    errno => 400,
39
);
39
);
40
my $status = '400 Bad Request';
40
my $status = '400 Bad Request';
41
if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
41
if ( C4::Context->is_internal_PSGI_request() ) {
42
    $status = '200 OK';
42
    $status = '200 OK';
43
}
43
}
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
(-)a/errors/401.pl (-1 / +1 lines)
Lines 37-43 $template->param ( Link Here
37
    errno => 401,
37
    errno => 401,
38
);
38
);
39
my $status = '401 Unauthorized';
39
my $status = '401 Unauthorized';
40
if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
40
if ( C4::Context->is_internal_PSGI_request() ) {
41
    $status = '200 OK';
41
    $status = '200 OK';
42
}
42
}
43
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
43
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
(-)a/errors/402.pl (-1 / +1 lines)
Lines 38-44 $template->param ( Link Here
38
    errno => 402,
38
    errno => 402,
39
);
39
);
40
my $status = '402 Payment Required';
40
my $status = '402 Payment Required';
41
if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
41
if ( C4::Context->is_internal_PSGI_request() ) {
42
    $status = '200 OK';
42
    $status = '200 OK';
43
}
43
}
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
(-)a/errors/403.pl (-1 / +1 lines)
Lines 38-44 $template->param ( Link Here
38
    errno => 403,
38
    errno => 403,
39
);
39
);
40
my $status = '403 Forbidden';
40
my $status = '403 Forbidden';
41
if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
41
if ( C4::Context->is_internal_PSGI_request() ) {
42
    $status = '200 OK';
42
    $status = '200 OK';
43
}
43
}
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
(-)a/errors/404.pl (-1 / +1 lines)
Lines 38-44 $template->param ( Link Here
38
    errno => 404,
38
    errno => 404,
39
);
39
);
40
my $status = '404 Not Found';
40
my $status = '404 Not Found';
41
if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
41
if ( C4::Context->is_internal_PSGI_request() ) {
42
    $status = '200 OK';
42
    $status = '200 OK';
43
}
43
}
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
(-)a/errors/500.pl (-1 / +1 lines)
Lines 38-44 $template->param ( Link Here
38
    errno => 500,
38
    errno => 500,
39
);
39
);
40
my $status = '500 Internal Server Error';
40
my $status = '500 Internal Server Error';
41
if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
41
if ( C4::Context->is_internal_PSGI_request() ) {
42
    $status = '200 OK';
42
    $status = '200 OK';
43
}
43
}
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
(-)a/opac/errors/400.pl (-1 / +1 lines)
Lines 38-44 $template->param ( Link Here
38
    errno => 400,
38
    errno => 400,
39
);
39
);
40
my $status = '400 Bad Request';
40
my $status = '400 Bad Request';
41
if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
41
if ( C4::Context->is_internal_PSGI_request() ) {
42
    $status = '200 OK';
42
    $status = '200 OK';
43
}
43
}
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
(-)a/opac/errors/401.pl (-1 / +1 lines)
Lines 38-44 $template->param ( Link Here
38
    errno => 401,
38
    errno => 401,
39
);
39
);
40
my $status = '401 Unauthorized';
40
my $status = '401 Unauthorized';
41
if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
41
if ( C4::Context->is_internal_PSGI_request() ) {
42
    $status = '200 OK';
42
    $status = '200 OK';
43
}
43
}
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
(-)a/opac/errors/402.pl (-1 / +1 lines)
Lines 38-44 $template->param ( Link Here
38
    errno => 402,
38
    errno => 402,
39
);
39
);
40
my $status = '402 Payment Required';
40
my $status = '402 Payment Required';
41
if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
41
if ( C4::Context->is_internal_PSGI_request() ) {
42
    $status = '200 OK';
42
    $status = '200 OK';
43
}
43
}
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
(-)a/opac/errors/403.pl (-1 / +1 lines)
Lines 38-44 $template->param ( Link Here
38
    errno => 403,
38
    errno => 403,
39
);
39
);
40
my $status = '403 Forbidden';
40
my $status = '403 Forbidden';
41
if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
41
if ( C4::Context->is_internal_PSGI_request() ) {
42
    $status = '200 OK';
42
    $status = '200 OK';
43
}
43
}
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
(-)a/opac/errors/404.pl (-1 / +1 lines)
Lines 38-44 $template->param ( Link Here
38
    errno => 404,
38
    errno => 404,
39
);
39
);
40
my $status = '404 Not Found';
40
my $status = '404 Not Found';
41
if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
41
if ( C4::Context->is_internal_PSGI_request() ) {
42
    $status = '200 OK';
42
    $status = '200 OK';
43
}
43
}
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
(-)a/opac/errors/500.pl (-2 / +1 lines)
Lines 38-44 $template->param ( Link Here
38
    errno => 500,
38
    errno => 500,
39
);
39
);
40
my $status = '500 Internal Server Error';
40
my $status = '500 Internal Server Error';
41
if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
41
if ( C4::Context->is_internal_PSGI_request() ) {
42
    $status = '200 OK';
42
    $status = '200 OK';
43
}
43
}
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
44
output_with_http_headers $query, $cookie, $template->output, 'html', $status;
45
- 

Return to bug 29420