Bugzilla – Attachment 171892 Details for
Bug 37526
Handle redirects in SUSHI requests
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37526: Handle redirects in SUSHI requests
Bug-37526-Handle-redirects-in-SUSHI-requests.patch (text/plain), 2.59 KB, created by
David Nind
on 2024-09-23 19:42:41 UTC
(
hide
)
Description:
Bug 37526: Handle redirects in SUSHI requests
Filename:
MIME Type:
Creator:
David Nind
Created:
2024-09-23 19:42:41 UTC
Size:
2.59 KB
patch
obsolete
>From 8c9d3493e4575a16da56bf6d6cd728f39ee3c6bf Mon Sep 17 00:00:00 2001 >From: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >Date: Tue, 30 Jul 2024 12:54:14 +0000 >Subject: [PATCH] Bug 37526: Handle redirects in SUSHI requests > >Test plan: >1) Apply test patch only. Run: >prove t/db_dependent/Koha/BackgroundJob/ErmSushiHarvester.t >2) Verify tests fail. >3) Apply this patch. Run tests again. Verify they pass. > >PA amended: Added test plan > >Signed-off-by: David Nind <david@davidnind.com> >--- > Koha/ERM/EUsage/UsageDataProvider.pm | 36 +++++++++++++++++++++------- > 1 file changed, 27 insertions(+), 9 deletions(-) > >diff --git a/Koha/ERM/EUsage/UsageDataProvider.pm b/Koha/ERM/EUsage/UsageDataProvider.pm >index f09e1983fc..b2358dfc62 100644 >--- a/Koha/ERM/EUsage/UsageDataProvider.pm >+++ b/Koha/ERM/EUsage/UsageDataProvider.pm >@@ -174,11 +174,8 @@ sub harvest_sushi { > $self->{report_type} = $args->{report_type}; > $self->{begin_date} = $args->{begin_date}; > $self->{end_date} = $args->{end_date}; >- my $url = $self->_build_url_query; >- my $request = HTTP::Request->new( 'GET' => $url ); >- my $ua = LWP::UserAgent->new; >- $ua->agent( 'Koha/' . Koha::version() ); >- my $response = $ua->simple_request($request); >+ my $url = $self->_build_url_query; >+ my $response = _handle_sushi_request($url); > > my $result = decode_json( $response->decoded_content ); > >@@ -278,10 +275,7 @@ sub test_connection { > $url .= '&requestor_id=' . $self->requestor_id if $self->requestor_id; > $url .= '&api_key=' . $self->api_key if $self->api_key; > >- my $request = HTTP::Request->new( 'GET' => $url ); >- my $ua = LWP::UserAgent->new; >- $ua->agent( 'Koha/' . Koha::version() ); >- my $response = $ua->simple_request($request); >+ my $response = _handle_sushi_request($url); > > if ( $response->{_rc} >= 400 ) { > my $message = $response->{_msg}; >@@ -525,6 +519,30 @@ sub _counter_file_size_too_large { > return 0; > } > >+=head3 _handle_sushi_response >+ >+Creates and sends the request based on a provided url >+Also handles any redirects >+ >+=cut >+ >+sub _handle_sushi_request { >+ my ($url) = @_; >+ >+ my $request = HTTP::Request->new( 'GET' => $url ); >+ my $ua = LWP::UserAgent->new; >+ $ua->agent( 'Koha/' . Koha::version() ); >+ my $response = $ua->simple_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); >+ } >+ >+ return $response; >+} >+ > =head3 _type > > =cut >-- >2.39.5
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 37526
:
169858
|
170381
|
171777
|
171778
|
171891
|
171892
|
172055
|
172056
|
172057