Bugzilla – Attachment 132299 Details for
Bug 29744
Harmonize psgi/plack detection methods
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29744: Harmonize psgi/plack detection methods
Bug-29744-Harmonize-psgiplack-detection-methods.patch (text/plain), 4.87 KB, created by
Martin Renvoize (ashimema)
on 2022-03-28 09:26:16 UTC
(
hide
)
Description:
Bug 29744: Harmonize psgi/plack detection methods
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-03-28 09:26:16 UTC
Size:
4.87 KB
patch
obsolete
>From b198e15c71dd81bdc739201784ab869112c3ecba Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 28 Mar 2022 10:23:58 +0100 >Subject: [PATCH] Bug 29744: Harmonize psgi/plack detection methods > >This patch updates and moves the existing psgi_env method out of Auth >and into Context and then replaces any manual references of the same >code to use the new method. >--- > C4/Auth.pm | 12 ++++++------ > C4/Auth_with_shibboleth.pm | 6 +++--- > C4/Context.pm | 14 ++++---------- > Koha/AuthUtils.pm | 4 +--- > about.pl | 2 +- > 5 files changed, 15 insertions(+), 23 deletions(-) > >diff --git a/C4/Auth.pm b/C4/Auth.pm >index b4edd2d932..ca800989cd 100644 >--- a/C4/Auth.pm >+++ b/C4/Auth.pm >@@ -53,14 +53,14 @@ use C4::Log qw( logaction ); > > use vars qw($ldap $cas $caslogout); > our (@ISA, @EXPORT_OK); >-BEGIN { >- sub psgi_env { any { /^psgi\./ } keys %ENV } > >- sub safe_exit { >- if (psgi_env) { die 'psgi:exit' } >- else { exit } >- } >+sub safe_exit { >+ if (C4::Context::psgi_env) { die 'psgi:exit' } >+ else { exit } >+} > >+ >+BEGIN { > C4::Context->set_remote_address; > > require Exporter; >diff --git a/C4/Auth_with_shibboleth.pm b/C4/Auth_with_shibboleth.pm >index e214a5307c..1eb14edc67 100644 >--- a/C4/Auth_with_shibboleth.pm >+++ b/C4/Auth_with_shibboleth.pm >@@ -81,7 +81,7 @@ sub get_login_shib { > > my $matchAttribute = $config->{mapping}->{ $config->{matchpoint} }->{is}; > >- if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { >+ if ( C4::Context::psgi_env ) { > return $ENV{"HTTP_".uc($matchAttribute)} || ''; > } else { > return $ENV{$matchAttribute} || ''; >@@ -126,7 +126,7 @@ sub _autocreate { > my %borrower = ( $config->{matchpoint} => $match ); > > while ( my ( $key, $entry ) = each %{$config->{'mapping'}} ) { >- if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { >+ if ( C4::Context::psgi_env ) { > $borrower{$key} = ( $entry->{'is'} && $ENV{"HTTP_" . uc($entry->{'is'}) } ) || $entry->{'content'} || ''; > } else { > $borrower{$key} = ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || ''; >@@ -144,7 +144,7 @@ sub _sync { > my %borrower; > $borrower{'borrowernumber'} = $borrowernumber; > while ( my ( $key, $entry ) = each %{$config->{'mapping'}} ) { >- if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { >+ if ( C4::Context::psgi_env ) { > $borrower{$key} = ( $entry->{'is'} && $ENV{"HTTP_" . uc($entry->{'is'}) } ) || $entry->{'content'} || ''; > } else { > $borrower{$key} = ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || ''; >diff --git a/C4/Context.pm b/C4/Context.pm >index b42f933b08..1c0933abdb 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -979,21 +979,15 @@ sub needs_install { > return ($self->preference('Version')) ? 0 : 1; > } > >-=head3 is_psgi_or_plack >+=head3 psgi_env > >-is_psgi_or_plack returns true if there is an environmental variable >+psgi_env 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; >-} >+sub psgi_env { any { /(^psgi\.|^plack\.)/i } keys %ENV }; > > =head3 is_internal_PSGI_request > >@@ -1006,7 +1000,7 @@ app > #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)/ ) ){ >+ if ( (__PACKAGE__->psgi_env) && ( $ENV{REQUEST_URI} !~ /^(\/intranet|\/opac)/ ) ){ > $is_internal = 1; > } > return $is_internal; >diff --git a/Koha/AuthUtils.pm b/Koha/AuthUtils.pm >index 8345f50a5f..1a1ccba830 100644 >--- a/Koha/AuthUtils.pm >+++ b/Koha/AuthUtils.pm >@@ -208,9 +208,7 @@ outside this context. > =cut > > sub get_script_name { >- # This is the method about.pl uses to detect Plack; now that two places use it, it MUST be >- # right. >- if ( ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) && $ENV{SCRIPT_NAME} =~ m,^/(intranet|opac)(.*), ) { >+ if ( ( C4::Context::psgi_env ) && $ENV{SCRIPT_NAME} =~ m,^/(intranet|opac)(.*), ) { > return '/cgi-bin/koha' . $2; > } else { > return $ENV{SCRIPT_NAME}; >diff --git a/about.pl b/about.pl >index 55ffc379fb..1fc49df76a 100755 >--- a/about.pl >+++ b/about.pl >@@ -123,7 +123,7 @@ if ($^O ne 'VMS') { > my $zebraVersion = `zebraidx -V`; > > # Check running PSGI env >-if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) { >+if ( C4::Context::psgi_env ) { > $template->param( > is_psgi => 1, > psgi_server => ($ENV{ PLACK_ENV }) ? "Plack ($ENV{PLACK_ENV})" : >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29744
:
132299
|
132975
|
133429
|
133430
|
140689
|
140690
|
140691
|
140692
|
140922