From ef7f056a7420d2c86cc93ab4a72dab826e2db57e Mon Sep 17 00:00:00 2001
From: David Cook <dcook@prosentient.com.au>
Date: Tue, 25 Feb 2020 13:28:05 +1100
Subject: [PATCH] Bug 24719: Remove use of CGI in
 C4::Context::set_remote_address()

This patch removes the CGI module usage, as it was causing file upload
problems for scripts like /cgi-bin/koha/tools/stage-marc-import.pl

Test plan:
1. Set koha_trusted_proxies in koha-conf.xml to 1.1.1.1
2. Clear Memcached
3. Try to upload MARCXML file to /cgi-bin/koha/tools/stage-marc-import.pl
4. Note that form below "Upload progress" never appears and errors show
in browser console
5. Apply the patch
6. Try to upload MARCXML file to /cgi-bin/koha/tools/stage-marc-import.pl
7. Note that form appears below "Upload progress"

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
---
 C4/Context.pm | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/C4/Context.pm b/C4/Context.pm
index 0fe571da2a..a846706d9c 100644
--- a/C4/Context.pm
+++ b/C4/Context.pm
@@ -1109,9 +1109,7 @@ variable to be set correctly.
 
 sub set_remote_address {
     if ( C4::Context->config('koha_trusted_proxies') ) {
-        require CGI;
-        my $cgi    = CGI->new;
-        my $header = $cgi->http('HTTP_X_FORWARDED_FOR');
+        my $header = $ENV{'HTTP_X_FORWARDED_FOR'};
 
         if ($header) {
             require Koha::Middleware::RealIP;
-- 
2.20.1