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

(-)a/C4/Context.pm (-2 / +6 lines)
Lines 1007-1013 this is a PSGI app or a CGI app, and implementing code as appropriate. Link Here
1007
1007
1008
=cut
1008
=cut
1009
1009
1010
sub psgi_env { any { /(^psgi\.|^plack\.)/i } keys %ENV };
1010
sub psgi_env {
1011
    my ( $self ) = @_;
1012
    return any { /^(psgi|plack)[._]/i } keys %ENV;
1013
}
1011
1014
1012
=head3 is_internal_PSGI_request
1015
=head3 is_internal_PSGI_request
1013
1016
Lines 1019-1026 app Link Here
1019
1022
1020
#NOTE: This is not a very robust method but it's the best we have so far
1023
#NOTE: This is not a very robust method but it's the best we have so far
1021
sub is_internal_PSGI_request {
1024
sub is_internal_PSGI_request {
1025
    my ( $self ) = @_;
1022
    my $is_internal = 0;
1026
    my $is_internal = 0;
1023
    if ( (__PACKAGE__->psgi_env) && ( $ENV{REQUEST_URI} !~ /^(\/intranet|\/opac)/ ) ){
1027
    if( $self->psgi_env && ( $ENV{REQUEST_URI} !~ /^(\/intranet|\/opac)/ ) ) {
1024
        $is_internal = 1;
1028
        $is_internal = 1;
1025
    }
1029
    }
1026
    return $is_internal;
1030
    return $is_internal;
(-)a/t/Context.t (-2 / +32 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use DBI;
20
use DBI;
21
use Test::More tests => 32;
21
use Test::More tests => 33;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
use YAML::XS;
24
use YAML::XS;
Lines 145-147 is( C4::Context->interface( 'CRON' ), 'cron', 'interface cron uc' ); Link Here
145
    $ENV{HTTPS} = 'ON';
145
    $ENV{HTTPS} = 'ON';
146
    is( C4::Context->https_enabled, 1, "ON HTTPS env returns 1");
146
    is( C4::Context->https_enabled, 1, "ON HTTPS env returns 1");
147
}
147
}
148
- 
148
149
subtest 'psgi_env and is_internal_PSGI_request' => sub {
150
    plan tests => 11;
151
152
    local %ENV = ( no_plack => 1 );
153
    is( C4::Context->psgi_env, q{}, 'no_plack' );
154
    $ENV{plackishere} = 1;
155
    is( C4::Context->psgi_env, q{}, 'plackishere is wrong' );
156
    $ENV{'plack.ishere'} = 1;
157
    is( C4::Context->psgi_env, 1, 'plack.ishere' );
158
    delete $ENV{'plack.ishere'};
159
    is( C4::Context->psgi_env, q{}, 'plack.ishere was here' );
160
    $ENV{'plack_ishere'} = 1;
161
    is( C4::Context->psgi_env, 1, 'plack_ishere' );
162
    delete $ENV{'plack_ishere'};
163
    $ENV{'psgi_whatever'} = 1;
164
    is( C4::Context->psgi_env, 1, 'psgi_whatever' );
165
    delete $ENV{'psgi_whatever'};
166
    $ENV{'psgi.whatever'} = 1;
167
    is( C4::Context->psgi_env, 1, 'psgi.whatever' );
168
    delete $ENV{'psgi.whatever'};
169
    $ENV{'PSGI.UPPERCASE'} = 1;
170
    is( C4::Context->psgi_env, 1, 'PSGI uppercase' );
171
172
    $ENV{'REQUEST_URI'} = '/intranet/whatever';
173
    is( C4::Context->is_internal_PSGI_request, 0, 'intranet not considered internal in regex' );
174
    $ENV{'REQUEST_URI'} = '/api/v1/tralala';
175
    is( C4::Context->is_internal_PSGI_request, 1, 'api considered internal in regex' );
176
    delete $ENV{'PSGI.UPPERCASE'};
177
    is( C4::Context->is_internal_PSGI_request, 0, 'api but no longer PSGI' );
178
};

Return to bug 29744