From af3ae06245cee74cd4bc0ce8f3a17a162f75b40e Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 16 Feb 2024 00:11:10 +0000 Subject: [PATCH] Bug 34478: Make plack.psgi change more comprehensive Signed-off-by: Jonathan Druart --- debian/templates/plack.psgi | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/debian/templates/plack.psgi b/debian/templates/plack.psgi index 4448a781e7..eeeeca2b08 100644 --- a/debian/templates/plack.psgi +++ b/debian/templates/plack.psgi @@ -48,13 +48,27 @@ use CGI qw(-utf8 ); # we will loose -utf8 under plack, otherwise Koha::Caches->flush_L1_caches(); Koha::Cache::Memory::Lite->flush(); + my %stateless_methods = ( + GET => 1, + HEAD => 1, + OPTIONS => 1, + TRACE => 1, + ); + + my %stateful_methods = ( + POST => 1, + PUT => 1, + DELETE => 1, + PATCH => 1, + ); + my $original_op = $q->param('op'); my $request_method = $q->request_method // q{}; - if ( $request_method eq 'GET' && defined $original_op && $original_op =~ m{^cud-} ) { - warn "Programming error - op '$original_op' must not start with 'cud-' for GET"; + if ( $stateless_methods{$request_method} && defined $original_op && $original_op =~ m{^cud-} ) { + warn "Programming error - op '$original_op' must not start with 'cud-' for $request_method"; $q->param( 'op', '' ); - $q->param( 'debug_programming_error', "'$original_op' must not start with 'cud-' for GET" ); - } elsif ( $request_method ne 'GET' && defined $q->param('op') && $original_op !~ m{^cud-} ) { + $q->param( 'debug_programming_error', "'$original_op' must not start with 'cud-' for $request_method" ); + } elsif ( $stateful_methods{$request_method} && defined $q->param('op') && $original_op !~ m{^cud-} ) { warn "Programming error - op '$original_op' must start with 'cud-' for $request_method"; $q->param( 'op', '' ); $q->param( 'debug_programming_error', "'$original_op' must start with 'cud-' for $request_method" ); -- 2.39.2