From 90e15fbd9ee90470daa1b48efef1db226899b974 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Fri, 12 Sep 2025 04:30:12 +0000 Subject: [PATCH] Bug 30614: [WIP] Fallback to a GET request if HEAD returns error status This is a WIP - feedback welcome. Sample MARC attached. Testing using: perl misc/cronjobs/check-url-quick.pl -v > test.txt grep -E "tand|wiley|natlib|cold|canterbury" test.txt --- 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 88e2d431145..060682e97ef 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