From d148f122000e2aab2ed1a325c645ab7badbddfe4 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Fri, 12 Sep 2025 04:30:12 +0000 Subject: [PATCH] Bug 30614: Fallback to a GET request if HEAD returns error status This enhancement makes a GET request as a fallback if HEAD returns an error status. This doesn't fix all of the errors produced by the sample error MARC attached - any further support is welcomed. To test: 1. Download MARC. Go to Cataloguing in the staff interface and stage the MARC file for import, then import. 2. Run the URL check job and confirm erroring URLs perl misc/cronjobs/check-url-quick.pl -v > test.txt grep -E "tand|wiley|natlib|cold|canterbury" test.txt 3. Apply patch and restart services 4. Repeat step 2 and notice 2 of the URLs are now returning 200 OK status codes. Sponsored-by: Earth Sciences New Zealand --- misc/cronjobs/check-url-quick.pl | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/misc/cronjobs/check-url-quick.pl b/misc/cronjobs/check-url-quick.pl index 78b8adc229a..6483b0b2849 100755 --- a/misc/cronjobs/check-url-quick.pl +++ b/misc/cronjobs/check-url-quick.pl @@ -27,6 +27,9 @@ use Koha::Biblios; use AnyEvent; use AnyEvent::HTTP qw( http_request ); use Encode qw( encode_utf8 ); +use HTTP::Request; +use LWP::UserAgent; +use URI; my ( $verbose, $help, $html ) = ( 0, 0, 0 ); my ( $host, $host_intranet ) = ( '', '' ); @@ -108,8 +111,21 @@ sub check_all_url { sub { my ( undef, $hdr ) = @_; $count--; - report( $hdr, $biblionumber, $url ) - if $hdr->{Status} !~ /^2/ || $verbose; + if ( $hdr->{Status} !~ /^2/ ) { + my $request = HTTP::Request->new( 'GET' => $url ); + my $ua = LWP::UserAgent->new; + $ua->agent($user_agent); + my $response = $ua->request($request); + if ( $response->is_redirect ) { + my $redirect_url = $response->header('Location'); + $redirect_url = URI->new_abs( $redirect_url, $url ); + $response = $ua->get($redirect_url); + } + my $status_code = substr( $response->status_line, 0, 3 ); + my $reason = substr( $response->status_line, 3 ); + report( { Status => $status_code, Reason => $reason }, $biblionumber, $url ) + if !$response->is_success || $verbose; + } }, ); } -- 2.39.5